The WHERE clause in SQL is used to filter rows from a table based on specific conditions. It allows you to retrieve only the rows that meet the specified criteria, thereby narrowing down the result set. The purpose of the WHERE clause is to extract data that satisfies a particular condition or set of conditions.
The syntax for using the WHERE clause in a SQL query is as follows:
SELECT column1, column2, ...
FROM table_name
WHERE condition;
In the above syntax, `column1`, `column2`, and so on represent the columns you want to select from the table, and `table_name` represents the name of the table you are querying.
The `condition` in the WHERE clause is a logical expression that defines the filtering criteria. It can include comparison operators (such as `=`, `<>`, `<`, `>`, `<=`, `>=`), logical operators (`AND`, `OR`, `NOT`), and other SQL functions and expressions.
For example, let's say we have a table called "Employees" with columns "EmployeeID," "FirstName," and "Salary." If we want to retrieve the details of employees whose salary is greater than 50000, we can use the following query:
SELECT EmployeeID, FirstName, Salary
FROM Employees
WHERE Salary > 50000;
The WHERE clause in this query specifies the condition `Salary > 50000`, which ensures that only the rows where the salary is greater than 50000 will be included in the result.
The WHERE clause can be combined with other SQL clauses like ORDER BY, GROUP BY, JOIN, and others to create more complex queries that fetch the desired data from a database.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
The WHERE clause in SQL is used to filter rows from a table based on specific conditions. It allows you to retrieve only the rows that meet the specified criteria, thereby narrowing down the result set. The purpose of the WHERE clause is to extract data that satisfies a particular condition or set of conditions.
The syntax for using the WHERE clause in a SQL query is as follows:
In the above syntax, `column1`, `column2`, and so on represent the columns you want to select from the table, and `table_name` represents the name of the table you are querying.
The `condition` in the WHERE clause is a logical expression that defines the filtering criteria. It can include comparison operators (such as `=`, `<>`, `<`, `>`, `<=`, `>=`), logical operators (`AND`, `OR`, `NOT`), and other SQL functions and expressions.
For example, let's say we have a table called "Employees" with columns "EmployeeID," "FirstName," and "Salary." If we want to retrieve the details of employees whose salary is greater than 50000, we can use the following query:
The WHERE clause in this query specifies the condition `Salary > 50000`, which ensures that only the rows where the salary is greater than 50000 will be included in the result.
The WHERE clause can be combined with other SQL clauses like ORDER BY, GROUP BY, JOIN, and others to create more complex queries that fetch the desired data from a database.