Operators used in MySQL
What are Operators in MySQL?
Operators are symbols used to specify a condition in a SQL statement in
MySQL. Below are the different types of operators used in MySQL.
MySQL Arithmetic Operators
Arithmetic operators are used to perform the arithmetic operations.
Arithmetic Operators are:-
Operator Description Example
+ Add SELECT 30 + 20;
- Subtract SELECT 30 - 20;
* Multiply SELECT 30 *20;
/ Divide SELECT 30/ 20;
% Modulo SELECT 30 % 20;
MySQL Bitwise Operators
Operator Description
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
MySQL Comparison Operators
The Comparison Operators in SQL compare two different data of SQL table and check
whether they are the same, greater, and lesser. The SQL comparison operators are used with
the WHERE clause in the SQL queries
Operator Description Example
= Equal to SELECT * FROM Products
WHERE Price = 18;
> Greater than SELECT * FROM Products
WHERE Price > 30;
< Less than SELECT * FROM Products
WHERE Price < 30;
>= Greater than or SELECT * FROM Products
equal to WHERE Price >= 30;
<= Less than or SELECT * FROM Products
equal to WHERE Price <= 30;
<> Not equal to SELECT * FROM Products
WHERE Price <> 28;
MySQL Compound Operators
Operator Description
+= Add equals
-= Subtract equals
*= Multiply equals
/= Divide equals
%= Modulo equals
&= Bitwise AND equals
^-= Bitwise exclusive equals
|*= Bitwise OR equals
MySQL Logical Operators
The Logical Operators in SQL perform the Boolean operations, which give two
results True and False. These operators provide True value if both operands match
the logical condition.
Operator Description
ALL TRUE if all of the subquery values meet the
condition
Example SELECT * FROM Products
WHERE Price > ALL (SELECT Price FROM Products WHERE Price > 500);
AND TRUE if all the conditions separated by AND is
TRUE
Example SELECT * FROM Customers
WHERE City = "London" AND Country = "UK";
ANY TRUE if any of the subquery values meet the
condition
Example SELECT * FROM Products
WHERE Price > ANY (SELECT Price FROM Products WHERE
Price > 50);
BETWEEN TRUE if the operand is within the range of
comparisons
Example SELECT * FROM Products
WHERE Price BETWEEN 50 AND 60;
EXISTS TRUE if the subquery returns one or more records
Example SELECT * FROM Products
WHERE EXISTS (SELECT Price FROM Products WHERE Price >
50);
IN TRUE if the operand is equal to one of a list of
expressions
Example SELECT * FROM Customers
WHERE City IN ('Paris','London');
LIKE TRUE if the operand matches a pattern
Example SELECT * FROM Customers
WHERE City LIKE 's%';
NOT Displays a record if the condition(s) is NOT TRUE
Example SELECT * FROM Customers
WHERE City NOT LIKE 's%';
OR TRUE if any of the conditions separated by OR is
TRUE
Example SELECT * FROM Customers
WHERE City = "London" OR Country = "UK";
SOME TRUE if any of the subquery values meet the
condition
Example SELECT * FROM Products
WHERE Price > SOME (SELECT Price FROM Products WHERE
Price > 20);