Logical Operators


☞ Logical operators are used to combine multiple conditions in a WHERE clause to filter rows from a table based on specific criteria.

☞ These operators are typically used in the WHERE clause of SELECT, UPDATE, DELETE.

☞ The commonly used relational operators in MySQL are AND, OR and NOT.

Syntax :

SELECT * FROM <table_name>
WHERE <condition>;

AND Operator

☞It displays a record and returns true value if all the conditions specified in the WHERE clause are true.

Example :

SELECT * FROM Student
WHERE fees=14020.50 AND gender='M';

OR Operator

☞ It displays a record and returns true value if either of the conditions specified in the WHERE clause are true.

Example :

SELECT * FROM Student
WHERE fees=14020.50 OR gender='M';

NOT Operator

☞ It returns a false if the condition holds true and vice-versa.

Example :

SELECT * FROM Student
WHERE fees!=14020.50;
NOTE : The order of precedence for logical operators is NOT, AND and OR.