Geek Slack

My SQL Tutorial
About Lesson



MySQL WHERE Clause


MySQL WHERE Clause

The WHERE clause in MySQL is used to filter records that match a specified condition.

Basic Syntax:

Example: Basic WHERE

SELECT column1, column2, ...
FROM table_name
WHERE condition;

This SQL command selects specific columns (column1, column2, …) from a table (table_name) where the specified condition is true.

Examples of WHERE Clause:

Filtering by Numeric Values:

SELECT * FROM users
WHERE age > 30;

Selects all columns from the users table where the age is greater than 30.

Filtering by Text Values:

SELECT * FROM products
WHERE category = 'Electronics';

Selects all columns from the products table where the category is ‘Electronics’.

Combining Conditions:

SELECT * FROM orders
WHERE total_amount > 1000 AND status = 'Delivered';

Selects all columns from the orders table where the total_amount is greater than 1000 and the status is ‘Delivered’.

Conclusion

The WHERE clause is essential in MySQL for filtering data based on specific conditions, allowing for targeted retrieval and manipulation of data within tables.

Join the conversation