We will see some comparison operators from MySQL in action with real-time table examples.
For this article, we will use this table products to perform various queries.
1. Operator = Equals
SELECT * FROM products
WHERE unit_price = 1.21;
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;
> operator produces values greater than the provided value in the query.
3. Operator < Lesser Than
SELECT * FROM Products
WHERE unit_price < 3;
< operator produces lesser values than the provided value in the query.
4. Operator >= Greater Than Or Equals
SELECT * FROM Products
WHERE unit_price >= 3;
- >= 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;
- <= 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;
- <> operator produces all the values other than the specified value in the query since it represents the negate/not operation.
- Log in to post comments