SQL WHERE Clause



Where Clause :

In SQL where clause is used for filtering the records.
If condition mentioned in the where clause is satisfied by the record then and then that record will be selected.

SQL WHERE Syntax

SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;

Demo Example :

In this example we are using our customer database. Consider following “CUSTOMER” table –

IDNAMEAGEADDRESSSALARY
1Raj20Pune1000.00
2Saurabh20Pune6000.00
3Omkar24Mumbai4000.00
4Anand23Pune3000.00
5Anmol29Goa1000.00
6Poonam25Delhi9000.00

Where Clause #1 : Select Customer living in Pune

Suppose we need to select all the customers that are living in Pune only then we can use below query –

SQL> Select * from CUSTOMER where city = 'Pune'

Above query will provide you following records

IDNAMEAGEADDRESSSALARY
1Raj20Pune1000.00
2Saurabh20Pune6000.00
4Anand23Pune3000.00

Where Clause #2 : Numeric Value

In the above example we have used single quote for specifying the value of the Column. In this example we will be using the numeric value as parameter in where clause.
Consider the below query –

SQL> Select * from CUSTOMER where ID = 3

Query will provide you following result –

IDNAMEAGEADDRESSSALARY
3Omkar24Mumbai4000.00

Where Clause #3 : Operators and Conditions

The following operators can be used in the WHERE clause:

OperatorDescription
=Equal
<>Not equal. Note: In some versions of SQL this operator may be written as !=
>Greater than
<Less than
>=Greater than or equal
<=Less than or equal
BETWEENBetween an range provided
LIKESearching for particular pattern
INSpecify multiple possible values for a column
#91;/table#93;
Consider the following query -
SQL> Select * from CUSTOMER where ID > 3 AND CITY = 'PUNE'
Output of the query will be –
IDNAMEAGEADDRESSSALARY
4Anand23Pune3000.00