0

I am very new and trying to learn how to use Select, Join, and Where with sqlite in android. Ideally this is what I want to return from the Database:

People who have the role id of 4 (Ranged):

select people.[name]
from people
join people_role
on people.[id] = people_role.[people_id]
where role_id = 4

What would the code be for returning People that have the role_id of 4?

Graham Borland
  • 60,055
  • 21
  • 138
  • 179
JoeyL
  • 1,295
  • 7
  • 28
  • 50
  • your code does return people with role_id 4, no? – zapl Sep 03 '12 at 13:15
  • @zapl I am not sure how to start, my buddy who is working on the back end gave me this to work with. Would I make a string and put the "select people.[name] ... role_id = 4" as is in a string and pass it in rawQuery()? Or is there some modification to string I would need to do? – JoeyL Sep 03 '12 at 13:25

1 Answers1

1

1- Create your database using SQLiteBrowser.

2- Keep the Database in assets folder

3- Follow this solution.

4- Find getTestData() in TestAdapter calss & replace it with :

 public Cursor getTestData() 
 { 
     try 
     { 
         String sql ="select people.[name]  
           from people  
           join people_role  
           on people.[id] = people_role.[people_id]  
           where role_id = 4 "; 

         Cursor mCur = mDb.rawQuery(sql, null); 
         if (mCur!=null) 
         { 
            mCur.moveToNext(); 
         } 
         return mCur; 
     } 
     catch (SQLException mSQLException)  
     { 
         Log.e(TAG, "getTestData >>"+ mSQLException.toString()); 
         throw mSQLException; 
     } 
 }
Community
  • 1
  • 1
Yaqub Ahmad
  • 27,569
  • 23
  • 102
  • 149