MySQL Comparison Operators

Profile picture for user arilio666

We will see some comparison operators from MySQL in action with real-time table examples.

mysql comparison operators

For this article, we will use this table products to perform various queries.

1. Operator = Equals

SELECT * FROM products
WHERE unit_price = 1.21;

Operator = Equals

The equal operator in this query has produced the unit_price exact value of 1.21, satisfying the condition.

2. Operator > Greater Than

SELECT * FROM Products
WHERE unit_price > 3;

Mysql Greater Than Operator

> operator produces values greater than the provided value in the query.

3. Operator < Lesser Than

SELECT * FROM Products
WHERE unit_price < 3;

MySQL less than operator

< operator produces lesser values than the provided value in the query.

4. Operator >= Greater Than Or Equals

SELECT * FROM Products
WHERE unit_price >= 3;

MySQL Greater Than Or Equals operator

  • >= operator produces values greater than or equal to the provided value in the query.

5. Operator <= Lesser Than Or Equals

SELECT * FROM Products
WHERE unit_price <= 3;

MySQL Less than equal to operator

  • <= operator produces values that are lesser than or equal to the provided value in the query.

6. Operator <> NOT

SELECT * FROM Products
WHERE unit_price <> 1.09;

MySQL not operator

  • <> operator produces all the values other than the specified value in the query since it represents the negate/not operation.
Tags