WHERE Clause

The SQLite WHERE clause is generally used with SELECT, UPDATE and DELETE statement to specify a condition while you fetch the data from one table or multiple tables.

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

WHERE clause is also used to filter the records and fetch only specific data.

Syntax:

SELECT column1, column2, columnN   

FROM table_name  

WHERE [condition]

Example:

In this example, we are using WHERE clause with several comparison and logical operators. like >, <, =, LIKE, NOT, etc.

We have a table student having the following data:

Sqlite Where clause 1

Example1:

Select students WHERE age is greater than or equal to 25 and fees is greater than or equal to 10000.00

SELECT * FROM STUDENT WHERE AGE >= 25 AND FEES >= 10000.00;   

Output:

Sqlite Where clause 2

Example2:

Select students form STUDENT table where name starts with ‘A’ doesn’t matter what come after ‘A’.

SELECT * FROM STUDENT WHERE NAME LIKE 'A%';  

Output:

Sqlite Where clause 3

Example3:

Select all students from STUDENT table where age is either 25 or 27.

SELECT * FROM STUDENT WHERE AGE IN ( 25, 27 );  

Output:

Sqlite Where clause 4

Example4:

Select all students from STUDENT table where age is neither 25 nor 27.

Output:

Sqlite Where clause 5

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *