Loading

MySQL Comparison Operators

MySQL Comparison Operators are used to compare two or more values or two or more queries or two or more expressions.

The following operators are called MySQL Comparison Operators:-

= (Equal to):- this operator is used to check equal value.  A few examples are:-

SELECT name, section FROM student WHERE age= ‘9’;

SELECT productname, quantity FROM Products WHERE Price = 30;

SELECT * FROM employee WHERE salary = 30000;

> (Greater Than):- Few examples are:-

SELECT name, section FROM student WHERE age > ‘9’;

SELECT productname, quantity FROM Products WHERE Price > 30;

SELECT * FROM employee WHERE salary > 30000;

< (Less Than):- Few examples are:-

SELECT name, section FROM student WHERE age < ‘9’;

SELECT productname, quantity FROM Products WHERE Price < 30;

SELECT * FROM employee WHERE salary < 30000;

>= (Greater Than and Equal to):- Few examples are:-

SELECT name, section FROM student WHERE age >= ‘9’;

SELECT productname, quantity FROM Products WHERE Price >= 30;

SELECT * FROM employee WHERE salary >= 30000;

<= (Less Than and equal to):- Few examples are:-

SELECT name, section FROM student WHERE age <= ‘9’;

SELECT productname, quantity FROM Products WHERE Price <= 30;

SELECT * FROM employee WHERE salary < 30000;

 <> or != (Not Equal to):- Few examples are:-

SELECT name, section FROM student WHERE age <> ‘9’;

SELECT productname, quantity FROM Products WHERE Price <> 30;

SELECT * FROM employee WHERE salary != 30000;

<=> (NULL-safe equal to operator):- Few examples are:- This operator performs an equality comparison like the = operator but returns 1 rather than NULL if both operands are NULL, and 0 rather than NULL if one operand is NULL.

SELECT 1 <=> 1, NULL <=> NULL, 1 <=> NULL;

output    -> 1, 1, 0

SELECT 1 = 1, NULL = NULL, 1 = NULL;

output  -> 1, NULL, NULL

Read also:-

MySQL Arithmetic Operators Example

MySQL Bitwise Operators

MySQL Comparison Functions

MySQL String Comparison Operator Functions

MySQL Compound Operators

MySQL Logical Operators

For more detail about operators please check the Manual

Share with:


Leave a Reply

Connect with:

z35W7z4v9z8w
Verified by ExactMetrics