The WHERE clause in MySQL is used in conjunction with the "SELECT", "UPDATE", "DELETE", and other SQL statements to filter rows based on specified conditions.
It allows us to "retrieve", "update", or "delete" only those rows that meet the specified criteria.
WHERE clause In MySQL can be used with different types of comparison operators such as `=(Equal Operator)`, `!=(Not Equal)`, `<(less than Operator)`, `>(Greater than Operator)`, `BETWEEN`, `IN`, `LIKE`, `IS NULL`, `NOT` and more.
SELECT columnName1, columnName2 FROM tableName WHERE condition;
columnName1, columnName2: The columns we want to retrieve from the table. We can use an asterisk (*) to select all columns.
tableName: The name of the table from which we want to retrieve data.
WHERE condition: The condition that specifies which rows to include in the result set.
The below query retrieves all columns from the `products` table where the `category` is equal to 'GAMES'.
SELECT * FROM products WHERE category = 'GAMES';
The below query retrieves all columns from the `products` table where the `price` is greater than `100`.
SELECT * FROM products WHERE price > 100;
The below query retrieves all columns from the `products` table where the `price` is less than `100`.
SELECT * FROM products WHERE price < 100;
Retrieves all products whose `category` is not equal to 'GAMES'.
SELECT * FROM products WHERE category != 'GAMES';
Retrieves all products whose `price` is between 500 to 1000.
SELECT * FROM products WHERE products BETWEEN 500 AND 1000;
Retrieves all products from the table where `category` is 'GAMES' or 'CLOTHING'.
SELECT * FROM products WHERE category IN ('GAMES', 'CLOTHING');
Retrieves all products whose `productName` starts with 'pu'.
Retrieves all products whose `productName` ends with 'bg'.
// Product Name Start with "pu" SELECT * FROM products WHERE products LIKE 'pu%'; // Product Name End with "bg" SELECT * FROM products WHERE products LIKE '%bg';