Logical Operators in MySQL
Operator are reserved word used in MySQL statements. Opeators perform the operation with WHERE clause. We can logical operators for perform logical operation in MySQL. The logical operators are those that are ture or false. They return a true or false value to combine one or more true or false value.
The Logical operator are:-
- AND(&&) Operator
- OR(||) Operator
- NOT(!) Operator
AND operator compares between two values and returns TRUE value when both
expression are TRUE and returns FALSE when either is FALSE. Otherwise return
Syntax of AND Operator:-
SELECT col1,col2 FROM table_name WHERE col=value AND col=value;
SELECT name,age,address FROM students WHERE age="18" AND address= "UTTARAKHAND";
OR operator compares between two values return TRUE when one of the
expression is TRUE and returns FALSE when either is FALSE. Otherwise return
Syntax of OR Operator:-
SELECT col1,col2 FROM table_name WHERE col=value OR col=value;
SELECT name,age,address FROM students WHERE age="18" OR address= "UTTARAKHAND";
NOT operator takes a single value as an argument and changes its value
from to true or from TRUe to FALSE.
Syntax of NOT Operator:-
SELECT col1,col2 FROM table_name WHERE NOT col=value;
SELECT name,age,address FROM students WHERE NOT age="18";
The IN operator checks a value within a value within a set of values separated by commas and retrieve the rows from the table which are matching.
The SQL BETWEEN operator tests an expression against a range. The range consists of a beginning, followed by an AND keyword and an end expression.
LIKE operator is used to compare a value to similar value using wildcard operators, and match the patterns specified in the query.
ANY compares a value to each value in a list or results from a query and evaluates to true if the result of an inner query contains at least one row.
ALL is used to select all records of a SELECT STATEMENT. It compares a value in a list or result from a query. The ALL must be the comparison operators and evaluates to TRUE if the query return no rows.
The EXISTS checks the existenc of a result of a subquery. The EXISTS subquery fetches at least one row. When no data is returned then this operator returns FALSE.