The WHERE clause in SQL is used to filter records that meet certain conditions. It allows you to retrieve only the data you're interested in by specifying the criteria.
By using the WHERE clause, you can refine your queries and make your results more relevant.
Hereβs the basic syntax to filter records with the WHERE clause:
SELECT column1, column2 FROM table_name WHERE condition;
In this structure, the condition could be any valid expression such as equality, comparisons, or logical operators.
Suppose we have a table called Employees with columns EmployeeID, Name, and Department.
SELECT Name, Department FROM Employees WHERE Department = 'Sales';
This query will return the names and departments of all employees working in the 'Sales' department.
You can combine multiple conditions using the AND or OR logical operators to create more complex filters.
SELECT Name, Age FROM Employees WHERE Department = 'Sales' AND Age > 30;
This will return employees who work in the 'Sales' department and are older than 30 years.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!