在SQLite中使用AND和OR [英] Use of AND and OR in SQLite

查看:86
本文介绍了在SQLite中使用AND和OR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 rawQuery(query,arg)从android中的SQLite访问记录.我在数据库中有两列,一列称为 friendsID ,第二列称为 emailSenderID .

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.

现在,如果我将邮件发送给我的朋友,则 emailSenderID -列将保存我的ID,而 friendsID -列将保存我的朋友的ID.如果我收到同一位朋友的电子邮件,则 friendsID -列将保存我的ID,而 emailSenderID -列将保存我朋友的ID.

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

请指导我如何在Android SQLite中使用 AND OR 运算符.

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

推荐答案

我猜你的意思是这样的:从 emailTable 中获取所有条目,其中 friendsID fID emailSenderID fID myID ."在这种情况下,您需要像这样将其分组:

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)

这篇关于在SQLite中使用AND和OR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆