![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find the minimum values of two or more fields in MySQL?
To find the minimum values of two or more fields, use LEAST() function from MySQL −
select least(yourColumnName1,yourColumnName2,...N) from yourTableName;
Let us first create a table −
mysql> create table DemoTable -> ( -> Date1 date, -> Date2 date, -> Date3 date -> ); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-03-31','2019-01-01','2019-03-05'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+------------+------------+------------+ | Date1 | Date2 | Date3 | +------------+------------+------------+ | 2019-03-31 | 2019-01-01 | 2019-03-05 | +------------+------------+------------+ 1 row in set (0.00 sec)
Following is the query to retrieve the minimum value in MySQL −
mysql> select least(Date1,Date2,Date3) from DemoTable;
Output
This will produce the following output −
+--------------------------+ | least(Date1,Date2,Date3) | +--------------------------+ | 2019-01-01 | +--------------------------+ 1 row in set (0.04 sec)
Advertisements