It is often required to filter records in the table based on some condition/s. To filter records using these conditions SQL WHERE clause is used. WHERE clause can be used in SELECT, UPDATE, DELETE, etc. statement.
In this article, we will learn how to use the SQL WHERE clause in the SELECT statement.
SQL WHERE CLAUSE Syntax
Select
column1, column2, columnN ....
from
table_name
WHERE
condition;
Sample Table
Employee
ID NAME SALARY ADDRESS DESIGNATION AGE 1 Peter Clark 90000.00 Daphne Road Manukau Manager 36 2 Alfredo Smith 60000.00 Pimpama Drive Rotorua Principal Engineer 32 3 James Cook 40500.00 Saint-Antoine Quebec SDE I 27 4 Hudson Stewart 45000.00 Stoney Creek Ontario SDE II 30 5 Nathan Taylor 55000.00 Long Street, Woolston SDE II 31
Example I
To fetch employees WHERE age is greater than 30 years
SELECT
*
FROM
Employee
WHERE
AGE > 30
ID NAME SALARY ADDRESS DESIGNATION AGE 1 Peter Clark 90000.00 Daphne Road Manukau Manager 36 2 Alfredo Smith 60000.00 Pimpama Drive Rotorua Principal Engineer 32 5 Nathan Taylor 55000.00 Long Street, Woolston SDE II 31
Example II
To fetch employees WHERE designation is SDE II
SELECT
*
FROM
Employee
WHERE
DESIGNATION =
'SDE II'
ID NAME SALARY ADDRESS DESIGNATION AGE 4 Hudson Stewart 45000.00 Stoney Creek Ontario SDE II 30 5 Nathan Taylor 55000.00 Long Street, Woolston SDE II 31