Loading

MySQL Comparison Operators

The following operators are called MySQL Comparison Operators:-

= (Equal to) :- this operator is used to check equal value.  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

Share with:


Leave a Reply

Connect with:

z35W7z4v9z8w