Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of AND and OR in SQLite

Tags:

android

sqlite

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.

like image 955
aftab Avatar asked Oct 24 '11 12:10

aftab


People also ask

Is SQLite slow?

The SQLite docs explains why this is so slow: Transaction speed is limited by disk drive speed because (by default) SQLite actually waits until the data really is safely stored on the disk surface before the transaction is complete. That way, if you suddenly lose power or if your OS crashes, your data is still safe.

What is SQLite format?

What is a SQLite File? A file with . sqlite extension is a lightweight SQL database file created with the SQLite software. It is a database in a file itself and implements a self-contained, full-featured, highly-reliable SQL database engine.

Is SQLite an operator?

An operator is a reserved word or a character used primarily in an SQLite statement's WHERE clause to perform operation(s), such as comparisons and arithmetic operations. Operators are used to specify conditions in an SQLite statement and to serve as conjunctions for multiple conditions in a statement.

Can SQLite read and write at same time?

First, by default, multiple processes can have the same SQLite database open at the same time, and several read accesses can be satisfied in parallel. In case of writing, a single write to the database locks the database for a short time, nothing, even reading, can access the database file at all.


1 Answers

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)
like image 107
Till Helge Avatar answered Oct 16 '22 18:10

Till Helge