SQL WHERE Clause, Where Condition in Query | Learn SQL


The SQL WHERE Clause is used when you want to retrieve specific or particular information from a database table excluding other irrelevant data.

For example, when you want to see the information about employees in production department only then you do not need the information about the employees in other departments. Retrieving information about all the employees would increase the processing time for the query.

So, SQL offers a functionality called WHERE clause, which we can use to restrict the data that is retrieved. The condition you provide in the WHERE clause filters the rows retrieved from the database tables and gives you only those rows which you expected to see.

SQL WHERE Clause | Tech-Mirror
SQL WHERE Clause | Tech-Mirror

Note: WHERE clause can be used along with SELECT, DELETE, UPDATE Commands.

Syntax of SQL WHERE Clause

For Example: To find the name of a employee with id 100, the query would be like:

Following Operators are used in the WHERE Clause

Operator Description
<> Not equal. Note: In some versions of SQL this operator may be written as !=
> Greater than
= Equal
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
IN To specify multiple possible values for a column

How to use expressions in the WHERE Clause?

For example: Lets consider the student table. If you want to display student name, current city, and a studentid grater than 120, the SELECT statement can be written as shown below

Note: Aliases defined in the SELECT Statement can be used in WHERE Clause.

Comparison Operators and Logical Operators are used in WHERE Clause refer above table.

For More >> SQL Insert Statement

Leave a Reply

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