nightcoder nightcoder - 1 month ago 7
Android Question

I am unable to create query to get desired data frrom different tables

I have Four tables created in SQLite database


  1. TaskTable : _id , user_id, title,description,project_id,position_id

  2. SelectedTagTable : _id,task_id

  3. PositionTable : _id,name

  4. ProjectTable : _id , name , position_id



Now i have the following where clause for filtering data that is


Where (user_id = 0) AND (SelectedTagTable.task_id = TaskTable._id) AND (TaskTable.position_id = PositionTable._id) AND (TaskTable.project_id = ProjectTable._id)


This is the query (where clause is same as mentioned above)
SELECT * FROM taskTable tk,selectedTagTable st, positionTable p, projectTable pp where tk.userId = 0 AND st.taskId = tk._id
AND tk.position = p._id AND tk.project = pp._id ;
that i have made ... but im unable to convert it for android using SQLite functions

I need this query or code snippet for the android SQLite. Can any one create the query to get this filtered data. Thanks in advance.

Answer

this return all the column for all the tables for user_id = 0

Select TaskTable.*, SelectedTagTable.*, PositionTable.*, ProjectTable.*
from TaskTable 
inner join SelectedTagTable on SelectedTagTable.task_id = TaskTable._id
inner join PositionTable on TaskTable.position_id = PositionTable._id  
inner join ProjectTable on TaskTable.project_id = ProjectTable._id
Where  user_id = 0

You need rawQuery method

  private final String MY_QUERY = "Select TaskTable.*, SelectedTagTable.*, PositionTable.*, ProjectTable,*
              from TaskTable 
              inner join SelectedTagTable on SelectedTagTable.task_id = TaskTable._id
              inner join PositionTable on TaskTable.position_id = PositionTable._id  
              inner join ProjectTable on TaskTable.project_id = ProjectTable._id
              Where  user_id = ?";


  db.rawQuery(MY_QUERY, new String[]{"0"});
Comments