MySQL AND Operator is one of the Logical Operator which is generally used in the WHERE Clause to apply multiple filters on the records returned by SELECT Statement. This operator returns the result as:
- 1, if all operands are non-zeros and not nulls.
- 0, if one of the operands is zero.
- NULL, If one of the operands is NULL, and remaining operands are non-zero.
Let us see how to use the MySQL Logical Operator AND in the WHERE Clause to filter the data. And, to explain the AND operator, we are going to use the below shown data.
MySQL AND Operator – Command prompt
In this example, we pass Ones, Zeros, and Null values with a different combination. It helps you to understand the Truth table behind the MySQL AND Operator.
-- MySQL AND Operator Example SELECT 0 AND 0; SELECT 1 AND 0; SELECT 1 AND 1; SELECT 1 AND NULL; SELECT 0 AND NULL; SELECT NULL AND NULL;
MySQL AND Operator Example
The MySQL AND Operator test multiple conditions in WHERE Clause. If all the conditions are TRUE, then only it displays the records.
-- MySQL AND Operator Example USE company; SELECT CustID, First_Name, Last_Name, Education, Profession, Yearly_Income, Sales FROM customers WHERE Profession LIKE '%Developer' AND Yearly_Income > 75000;
You can also use AND operator between three or 4 conditions. Let us apply three conditions using MySQL AND Operator
-- MySQL AND Operator Example USE company; SELECT CustID, First_Name, Last_Name, Education, Profession, Yearly_Income, Sales FROM customers WHERE Profession LIKE '%Developer' AND Yearly_Income > 75000 AND Sales > 10000;
The above statement returns all the Customers available in the Customers table whose Profession contains Developer, Yearly Income is greater than 75000, and Sales is greater than 10000.