For this, use MySQL MIN(). Let us first create a −
mysql> create table DemoTable1414 -> ( -> BookTitle varchar(40), -> BookPrice int -> ); Query OK, 0 rows affected (0.82 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1414 values('Deep dive using java',560); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1414 values('C++ in depth',360); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1414 values('Data structure in C',590); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1414 values('Algorithm in C++',1090); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1414 values('Java in Depth',360); Query OK, 1 row affected (0.33 sec)
Display all records from the table using select −
mysql> select * from DemoTable1414;
This will produce the following output −
+----------------------+-----------+ | BookTitle | BookPrice | +----------------------+-----------+ | Deep dive using java | 560 | | C++ in depth | 360 | | Data structure in C | 590 | | Algorithm in C++ | 1090 | | Java in Depth | 360 | +----------------------+-----------+ 5 rows in set (0.00 sec)
Following is the query to select multiple book titles that share the minimum price value−
mysql> select BookTitle from DemoTable1414 -> where BookPrice= ( select min(BookPrice) from DemoTable1414);
This will produce the following output −
+---------------+ | BookTitle | +---------------+ | C++ in depth | | Java in Depth | +---------------+ 2 rows in set (0.00 sec)