From the diagram below, i have two tables A and B. I have access to year and myid to select each record at a time. If i select record 1 in Table A, i will select its corresponding record 1 in Table B based on year and myid. If i select record 2 in Table A, i will select its corresponding record 2 in Table B based on year and myid; etc. which will finally look like Table C output below. Maybe using DISTINCT and INNER JOIN statements or otherwise you seem correct.
My question is: How can i compose SQL Query to select each record based on year and myid without repeating record or selecting more than one record at a time?
NOTE: This below is my attempt, in my real application; Table A are B represent variable names for multiple databases in my own query. "year" doesn't seem to work in my composed query, it makes selection only based on "myid" which selects only last '1' in myid; it makes my query to be wrong.
Dim rs As ResultSet = B4XPages.MainPage.sql1.ExecQuery("SELECT DISTINCT * FROM " & Table A & " INNER JOIN " & Table B & " WHERE " & Table A & ".year = " & Table B & ".year AND " & Table A & ".myid = " & Table B & ".myid AND " & Table B & ".myid =" & B4XPages.MainPage.ppq2.rowidanswt & " GROUP BY " & Table A & ".myid")
'
My question is: How can i compose SQL Query to select each record based on year and myid without repeating record or selecting more than one record at a time?
NOTE: This below is my attempt, in my real application; Table A are B represent variable names for multiple databases in my own query. "year" doesn't seem to work in my composed query, it makes selection only based on "myid" which selects only last '1' in myid; it makes my query to be wrong.
Dim rs As ResultSet = B4XPages.MainPage.sql1.ExecQuery("SELECT DISTINCT * FROM " & Table A & " INNER JOIN " & Table B & " WHERE " & Table A & ".year = " & Table B & ".year AND " & Table A & ".myid = " & Table B & ".myid AND " & Table B & ".myid =" & B4XPages.MainPage.ppq2.rowidanswt & " GROUP BY " & Table A & ".myid")
'
Last edited: