The WHERE Clause

In this lesson, we will learn how to use the WHERE clause in SQL to view specific data from table.

The WHERE clause

The SQL WHERE clause is used to specify a condition while fetching the data from a single table. If the given condition is satisfied, then those specific records are returned from the table.

Syntax

The basic syntax of the SELECT statement with the WHERE clause is as shown below:

SELECT column1, column2, ... columnN 

FROM table_name

WHERE [condition];

You can specify a condition using the comparison or logical operators like >, <, =, LIKE, NOT, etc.

Example #1

Let’s consider the CUSTOMERS table again.

ID NAME AGE ADDRESS SALARY
1 Mark 32 Texas 50000.00
2 John 25 NY 65000.00
3 Emily 23 Ohio 20000.00
4 Bill 25 Chicago 75000.00
5 Tom 27 Washington 35000.00
6 Jane 22 Texas 45000.00

Let’s say we want to fetch the ID, Name and Salary fields from the CUSTOMERS table, provided that the salary of the customer is greater than $50,000.

So when we write our SQL query, will get the following result:

Get hands-on with 1400+ tech skills courses.