Multiple WHERE Clause Conditionals Using the MySQL AND Logical Operator

Oftentimes, you need multiple filter conditionals in a WHERE clause in order to target specific rows of data. Continue reading this blog post and learn how to use the AND logical operator in WHERE clause queries…

The Newsletter for PHP and MySQL Developers

Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.

Practice Data

For the practice queries in this post, I’m using the ‘category’ table from the well-known Sakila database:

SELECT *
FROM category;

MySQL AND Logical Operator

How you use the AND logical operator in the WHERE clause is quite easy. Simply separate each individual conditional you want to test with the AND keyword.

See this example query:

SELECT *
FROM category
WHERE category_id = 2
AND
name = 'Comedy';

Knowing what data is present in the ‘category’ table, how many rows do you think this query will return?

Let’s see…

No rows are returned. Zero…

Here is why…

There are 2 conditionals separated by the AND keyword in this WHERE clause:

  • category_id = 2
  • name = ‘Comedy’

In order for any row to be returned in this SELECT query, the ‘category_id’ column value must equal 2, and the ‘name’ column value must equal ‘Comedy’. Yes, there is a row with a ‘category_id’ column value of 2. There is also a row with a ‘name’ column value of ‘Comedy’.

However, they are not one in the same (or same row).

Therefore, you should understand when using the AND logical operator, each conditional separated by AND must evaluate to TRUE in order for any row(s) to be included in the returned result set.

Let’s see what that looks like with this example SELECT query:

SELECT *
FROM category
WHERE category_id = 2
AND
name = 'Animation';

This is the only row in the ‘category’ table in which the ‘category_id’ column value is 2 (evaluates to TRUEand the ‘name’ column value is ‘Animation’ (also evaluates to TRUE).

Multiple AND logical operators in the WHERE clause

You can absolutely include multiple AND logical operators in the WHERE clause. Shown in this next query example, I now have 3 conditionals being tested:

SELECT *
FROM category
WHERE category_id = 2
AND
name = 'Animation'
AND
DATE(last_update) = '2006-02-15';

Again, each conditional test must evaluate to TRUE for a row to be included in the returned query results:

Should any one of the conditional tests evaluate as FALSE, the row will not be included:

SELECT *
FROM category
WHERE category_id = 2
AND
name = 'Animation'
AND
DATE(last_update) = '2006-02-14'; -- oops, different day

In this particular query, the conditionals category_id = 2 and name = ‘Animation’ evaluate to TRUE.

But, the conditional, DATE(last_update) = ‘2006-02-14’ evaluates to FALSE. Therefore, no rows are returned from this query.


Discover premium articles, in-depth guides, instructional videos, and much more by joining the “MySQL Learning Tier” membership. You have access to exclusive content unpublished anywhere else with this membership. With new content being added regularly, continue learning MySQL at any level.


Using the AND logical operator in the WHERE clause enables you to place super-specific constraints on which row(s) are returned or targeted in a query.

Recommended Reading

Visit any of these blog posts to learn more about how to use MySQL:


I appreciate you reading my content. Support me today with a Tip if you would like. Thank you! 🙏🏻


Thank you for reading this post. Please share it with someone else who would enjoy it as well.




Josh Otwell has a passion to grow as a PHP Developer, SQL expert, and technical blogger/writer.

Disclaimer: The majority of examples in this post, are performed in a personal development/learning workstation environment and should not be considered production quality or ready. Your particular goals and needs may vary. Like always, just because you can do something doesn’t mean you should. My opinions are my own.

More ways I can help

Disclosure: Some of this blog post’s services and product links are affiliate links. At no additional cost to you, should you make a purchase by clicking through one of them, I will receive a commission.

The Newsletter for PHP and MySQL Developers

Receive a copy of my ebook, “10 MySQL Tips For Everyone”, absolutely free when you subscribe to the OpenLampTech newsletter.

One thought on “Multiple WHERE Clause Conditionals Using the MySQL AND Logical Operator

Hey thanks for commenting! Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.