What is the use of comparison operators with MySQL subquery?

MySQLMySQLi Database

The subquery can return at most one value. The value can be the result of an arithmetic expression or a column function. MySQL then compares the value that results from the subquery with the value on the other side of the comparison operator. MySQL subquery can be used before or after any of the comparison operators like =, >, >=, <, <=, !=, <>, <=>. Following is the example in which we are using a subquery with a < comparison operator.

Example

mysql> SELECT * from Cars WHERE Price < (SELECT AVG(Price) FROM Cars);
 +------+--------------+---------+
| ID   | Name         | Price   |
+------+--------------+---------+
| 1    | Nexa         | 750000  |
| 2    | Maruti Swift | 450000  |
| 5    | Alto         | 250000  |
| 6    | Skoda        | 1250000 |
| 8    | Ford         | 1100000 |
+------+--------------+---------+
5 rows in set (0.00 sec)

Similarly, the subquery can be used with other comparison operators too.

raja
Published on 21-Feb-2018 13:20:19
Advertisements