Android sqlite选择Join Where

时间:2012-09-03 13:04:45

标签: android database sqlite

我很新,并且正在尝试学习如何在android中使用Select,Join和where with sqlite。理想情况下,这是我想从数据库返回的内容:

角色ID为4(远程)的人:

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

返回具有role_id为4的人员的代码是什么?

1 个答案:

答案 0 :(得分:1)

1-使用SQLiteBrowser创建数据库。

2-将数据库保留在资产文件夹

3-关注this solution

4-在TestAdapter calss&中查找 getTestData()将其替换为:

 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; 
     } 
 }