SQL WHERE Clause

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

IDNAMESALARYADDRESSDESIGNATIONAGE
1Peter Clark90000.00Daphne Road ManukauManager36
2Alfredo Smith60000.00Pimpama Drive RotoruaPrincipal Engineer32
3James Cook40500.00Saint-Antoine QuebecSDE I27
4Hudson Stewart45000.00Stoney Creek OntarioSDE II30
5Nathan Taylor55000.00Long Street, WoolstonSDE II31

Example I

  • To fetch employees WHERE age is greater than 30 years
SELECT * FROM Employee WHERE AGE > 30
IDNAMESALARYADDRESSDESIGNATIONAGE
1Peter Clark90000.00Daphne Road ManukauManager36
2Alfredo Smith60000.00Pimpama Drive RotoruaPrincipal Engineer32
5Nathan Taylor55000.00Long Street, WoolstonSDE II31

Example II

  • To fetch employees WHERE designation is SDE II
SELECT * FROM Employee WHERE DESIGNATION = 'SDE II'
IDNAMESALARYADDRESSDESIGNATIONAGE
4Hudson Stewart45000.00Stoney Creek OntarioSDE II30
5Nathan Taylor55000.00Long Street, WoolstonSDE II31

Liked the article? Share this on

Leave a Comment

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