Android db.query where clause

SQLite - WHERE Clause

The SQLite WHERE clause is used to specify a condition while fetching the data from one table or multiple tables.

If the given condition is satisfied, means true, then it returns specific value from the table. You would use WHERE clause to filter the records and fetching only necessary records.

Android db.query where clause

The WHERE clause not only used in SELECT statement, but it is also used in UPDATE, DELETE statement, etc. which we would study in subsequent chapters.

The basic syntax of SQLite SELECT statement with WHERE clause is as follows:

ads

You can specify a condition using Comparision or Logical Operators like >, <, =, LIKE, NOT, etc. Consider COMPANY table has the following records:

Here are simple examples showing usage of SQLite Logical Operators. Following SELECT statement lists down all the records where AGE is greater than or equal to 25 AND salary is greater than or equal to 65000.00:

Following SELECT statement lists down all the records where AGE is greater than or equal to 25 OR salary is greater than or equal to 65000.00:

Following SELECT statement lists down all the records where AGE is not NULL which means all the records because none of the record is having AGE equal to NULL:

Following SELECT statement lists down all the records where NAME starts with 'Ki', does not matter what comes after 'Ki'.

Following SELECT statement lists down all the records where NAME starts with 'Ki', does not matter what comes after 'Ki':

Following SELECT statement lists down all the records where AGE value is either 25 or 27:

Following SELECT statement lists down all the records where AGE value is neither 25 nor 27:

Following SELECT statement lists down all the records where AGE value is in BETWEEN 25 AND 27:

Following SELECT statement makes use of SQL sub-query where sub-query finds all the records with AGE field having SALARY > 65000 and later WHERE clause is being used along with EXISTS operator to list down all the records where AGE from the outside query exists in the result returned by sub-query:

Android db.query where clause

Following SELECT statement makes use of SQL sub-query where sub-query finds all the records with AGE field having SALARY > 65000 and later WHERE clause is being used along with > operator to list down all the records where AGE from outside query is greater than the age in the result returned by sub-query:

Related posts

  • The Best Ereader for Android Reading ebooks on Android used to be just okay. Now it's awesome. While there are plenty of sweet apps for reading books on your phone or tablet, Play Books has...

  • Video: Hands-on With New Instagram Video on Android Not that it was much of a surprise after a couple of reports broke the news in the days leading up to today’s Facebook event, but yes, they...

  • 4 Pics 1 Word Answers & Cheats 4 Pics 1 Word answers, cheats, and hints will show you how to beat all levels and letters of the game for iPhone, iPod, iPad, and Android. Guess the word that the...

  • Minecraft: Pocket Edition (for Android) Solid mining and crafting experience. Looks and plays great. Dead simple multiplayer. Continuous development. Not as deep as the PC version. Some touch...

  • [Android] What Is Superuser Gaining root on an Android device is not attained by unlocking the bootloader, or installing a custom recovery, but by flashing a small file called superuser....