How to recover a value from two table using sqlite android?

advertisements

I need to retrieve value from two table and display it in a recyclerview so far i have tried joins but the results doesn't seems as i expected. Now let me post my problem in detail i have two table namely call and travel here is the data as below:

Call Table;

PK_ID  INC_ID   DES   CHECKIN  CHECKOUT  FLAG
-----  ------   ---   -------  --------  ----
 1       2      Test  12:20    14:50      1

Travel Table:

PK_ID  INC_ID   LAT   LONG  FLAG
-----  ------   ---   ----  ----
   1     2      11.4  11.5   2

My Expected result shoulbe something like this:

Caal_PK_ID    Travel_PK_Id   INC_ID   Checkin  Checkout FLAG  LAT    LONG
----------    ------------   ------   -------  -------- ----  ---    ----
   1                0          2       12:20     14:50   1     null  null 

   0                1          2        null      null   2     11.4  11.5

How to produce this desired result by using joins am getting combined results i don't want that i need results like this how can i query this let me post my what i have tried so far

 String visitquery= "SELECT * FROM " + VisitModel.Visit_Table + " ,"  + VisitModel.Visit_TravelTable  + " where "   +VisitModel.Visit_IncidentID + " =  "+  id +  " and " +  VisitModel.Visit_IncidentID  + " = " + id ;

not getting results at can anyone please post anysolution for this.


To do this you need to try JOIN For the table, here i have modified your query to use INNER JOIN feature which will return the result that you want.

"SELECT * FROM " + VisitModel.Visit_Table + " as v INNER JOIN"  + VisitModel.Visit_TravelTable  + " as t where "   +v.Visit_IncidentID + " =  "+  id +  " and " +  v.Visit_IncidentID  + " = " + id ;