问题
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