MySQL - WHERE CLAUSE


The MySQL Where clause is used to filter records that meet specific conditions. It is commonly used in SELECT, UPDATE, DELETE, and other SQL statements to specify which rows should be included or affected by the query.

Syntax
SELECT column1,column2,column3... FROM table_name where condition;
Demo Database:
  • Table Name : products
product_id product_name product_code price unit category_id
1 The Psychology 7550 250.00 Piece 1
2 Stories for Children 3098 350.00 Piece 1
3 Harry Potter 8472 275.00 Piece 1
4 Tecno Spark 9468 8000.00 Nos 2
5 Samsung Galaxy 7188 10000.00 Nos 2
6 Panasonic Eluga 3433 7000.00 Nos 2
7 Lenovo IdeaPad 6708 45000.00 Nos 3
8 ASUS Celeron Dual Core 3583 43000.00 Nos 3
1) WHERE Clause Example

Select all product name from products table with specific unit.

Example
SELECT * FROM products where unit = 'Piece';
Try it Yourself
2) WHERE Clause with AND Operator

Let's find out all those products with unit 'Nos' and price less than 5000.

Example
SELECT * FROM products where unit='Nos' and price <= 5000;
Try it Yourself
Where clause Operators

Operator Description
= Equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
<> Not equal (can also be written as !=)
BETWEEN Between a certain range
LIKE Search for a pattern
IN Specify multiple possible values