Where Condition In Sql in SQL
The WHERE condition in SQL is used to filter records based on a specified criterion. It helps you retrieve, update, or delete only those rows that meet certain conditions.
What is the WHERE Condition?
It’s a clause that follows
SELECT,UPDATE, orDELETE.Defines the criteria that rows must satisfy to be affected or retrieved.
Supports various operators and expressions.
Basic Syntax
SELECT column1, column2, ...FROM table_nameWHERE condition;Common Operators Used in WHERE
| Operator | Description | Example |
|---|---|---|
= | Equal to | WHERE Age = 30 |
< | Less than | WHERE Price < 100 |
> | Greater than | WHERE Salary > 50000 |
<= | Less than or equal to | WHERE Date <= '2025-06-01' |
>= | Greater than or equal to | WHERE Score >= 80 |
<> or != | Not equal to | WHERE Status <> 'Active' |
BETWEEN | Within a range | WHERE Age BETWEEN 18 AND 25 |
IN | Matches any value in a list | WHERE Country IN ('US','CA') |
LIKE | Pattern matching | WHERE Name LIKE 'J%' |
IS NULL | Checks for NULL values | WHERE EndDate IS NULL |
Example Queries
-- Select employees older than 30SELECT * FROM EmployeesWHERE Age > 30;-- Select orders placed in 2025SELECT * FROM OrdersWHERE OrderDate BETWEEN '2025-01-01' AND '2025-12-31';-- Select customers from USA or CanadaSELECT * FROM CustomersWHERE Country IN ('USA', 'Canada');-- Select products with name starting with 'A'SELECT * FROM ProductsWHERE ProductName LIKE 'A%';If you want, I can help you build more complex WHERE conditions or explain specific use cases!