How to use the WHERE clause in MySQL to filter conditions?

In MySQL, you can use the WHERE clause to filter query results based on specific conditions. You can add the WHERE clause after the FROM clause in the SELECT statement and specify the conditions to apply.

For example, here is a simple example of selecting all customers with the last name “Smith” from a table named “customers”:

SELECT * FROM customers
WHERE last_name = 'Smith';

You can use multiple conditions combined with the WHERE clause, for example:

SELECT * FROM customers
WHERE last_name = 'Smith' AND city = 'New York';

In the WHERE clause, you can also use comparison operators (such as =, <, >, <=, >=, <>), logical operators (such as AND, OR, NOT), as well as condition expressions like IN, BETWEEN, and LIKE to define more complex filtering criteria.

It is important to note that the WHERE clause is optional, and if omitted, the query will return all rows in the table.

Leave a Reply 0

Your email address will not be published. Required fields are marked *