MySQL Operators

These are the following mostly used MySQL operators -

Operator Name Description
AND, && Logical AND
BINARY Cast a string to binary string
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
= Equal Operator
>= Greater than or equal operator
<= Less than or equal operator
< Greater than operator
> Less than operator
LIKE Simple Pattern Matching
NOT LIKE Negation of Simple Pattern Matching
NOT, ! Negates Value
|| Logical OR

Examples

These are the some operator examples. Suppose, we have students table as follows -

baseurl.'/images/students.jpg'; ?> alt="students table">

Greater than
The given query returns all the students whose age are greater than 10.

SELECT * FROM students WHERE age > 10;
baseurl.'/images/greaterthan.jpg'; ?> alt="greater than">

Less than
The given query returns all the students whose age are less than 11.

SELECT * FROM students WHERE age < 11;
baseurl.'/images/lessthan.jpg'; ?> alt="less than">

Greater than or equal operator
The given query returns all the student whose age are greater than or equals to 11.

SELECT * FROM students WHERE age >= 10;
baseurl.'/images/greatethanequal.jpg'; ?> alt="greater than equal">

LIKE operator
The given query returns all the students whose 'first_name' starts with 'j'.

SELECT * FROM students WHERE first_name LIKE 'j%';
baseurl.'/images/like.jpg'; ?> alt="like">

Logical OR operator
The given query returns all those students either whose 'first_name' starts with 'j' or study in class '6C'.

SELECT * FROM students WHERE first_name LIKE 'j%' OR class = '6C';
baseurl.'/images/multipleopertor.jpg'; ?> alt="like">