Skip to main content

The WHERE Clause

Premium

Welcome to the next lesson! In this lesson, we'll dive deeper into the WHERE clause and the logical operators that SQL provides us.

The WHERE clause is a fundamental part of SQL that allows you to filter data based on specific conditions. It can be used to filter rows in a SELECT statement, as well as UPDATE or DELETE statements.

Here’s a quick example:

SQL
SELECT * FROM table_name WHERE condition;

The condition here can be any boolean expression or combination of expressions.

Comparing values with <, >, =, !=

The comparison operators are used to compare the value in a given column to a specific value or the value of another column. Here are the operators you’ll need to know:

Here's an example of how to use these comparison operators in a SELECT statement:

SQL
SELECT * FROM courses WHERE duration < 10;

In this example, the SELECT statement is returning all columns (SELECT *) from the courses table where the duration is less than 10.

In this lesson, we learned about the WHERE clause in SQL and how to use it to filter data using comparison operators. By using the WHERE clause, we can specify conditions that must be met before the data can be returned.

Try it yourself

Given a database of customers, find all customers with the first name "Bruce".