SQL WHERE Clause

The SQL WHERE clause is used to filter records from a database table. It is an important part of any SQL query and is commonly used to specify which rows to include or exclude in the result set. WHERE is a powerful operation and can be used to select only the rows that meet certain conditions, such as matching a specific value or range of values.

Syntax

SELECT column1, column2, ...
FROM table_name
WHERE condition;
    

Example

SELECT *
FROM customers
WHERE city = 'New York';
    

This example selects all columns and rows from the "customers" table where the city is 'New York'.

Operators

You can use these operators in combination with AND, OR, and parentheses to create complex conditions. For example:

SELECT * FROM customers WHERE city = 'New York' AND (age >= 30 AND age <= 50)

You can learn more about these and other advanced topics in our SQL tutorials and references.