Use of AND and OR in SQLite

旧街凉风 提交于 2021-01-17 17:33:29

问题


I want to access records from SQLite in android using rawQuery(query,arg). I have two columns in database one called friendsID and 2nd called emailSenderID.

Now If I send mail to my friend emailSenderID-column will save my ID and friendsID-column save my friend's ID. If I receive an email from same friend then friendsID-column will save my ID and emailSenderID-column will save my friend's ID.

Now, If I wanna fetch record like this:

Select * from emailTable where friendsID =fID 
and emailSenderID=fID 
OR emailSenderID=myID

Please guide me how I can use AND and OR operators for Android SQLite.


回答1:


I guess you mean something like this: "Get me all entries from emailTable where friendsID is fID and emailSenderID is either fID or myID." In that case you need to group it like this:

 SELECT * FROM emailTable WHERE friendsID=fID AND 
     (emailSenderID=fID OR
     emailSenderID=myID)


来源:https://stackoverflow.com/questions/7875473/use-of-and-and-or-in-sqlite

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!