In the last post, we have seen the usage of the WHERE clause. In this post, you will see AND, OR, and NOT operators in MySQL. These operators are used to filter the data based on conditions. We can use them with the WHERE clause as well as we can use multiple and different operators in one command.
- The AND operator will display records if and only if, the conditions separated by AND are TRUE.
- The OR operator will display records if any of the conditions separated by OR is TRUE.
- The NOT operator will display a record if the condition is NOT TRUE.
Commands
AND syntax
select * from table_name where condition1 AND condition2 AND condition3 AND .... ;
OR syntax
select * from table_name where condition1 OR condition2 OR condition3 OR ...;
NOT syntax
select * from table_name where NOT condition;
Watch the following video to get more ideas on AND, OR, and NOT operators in MySQL