Get the minimum value from a list with multiple columns in MySQL?

MySQLMySQLi Database

Let us first create a table −

mysql> create table DemoTable756 (
   Value1 int,
   Value2 int,
   Value3 int
);
Query OK, 0 rows affected (0.62 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable756 values(10,20,14);
Query OK, 1 row affected (0.22 sec)
mysql> insert into DemoTable756 values(20,34,17);
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable756 values(200,134,789);
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable756 values(139,98,99);
Query OK, 1 row affected (0.17 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable756;

This will produce the following output -

+--------+--------+--------+
| Value1 | Value2 | Value3 |
+--------+--------+--------+
|     10 |     20 |     14 |
|     20 |     34 |     17 |
|    200 |    134 |    789 |
|    139 |     98 |     99 |
+--------+--------+--------+
4 rows in set (0.00 sec)

Following is the query to get minimum value from a list with multiple columns −

mysql> select least(Value1,Value2,Value3) from DemoTable756;

This will produce the following output -

+-----------------------------+
| least(Value1,Value2,Value3) |
+-----------------------------+
|                          10 |
|                          17 |
|                         134 |
|                          98 |
+-----------------------------+
4 rows in set (0.00 sec)
raja
Published on 03-Sep-2019 11:31:27
Advertisements