
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Minimum Score from Four Columns in MySQL
To find a minimum score from the entire four columns, use MySQL LEAST() function. Let us first create a table −
mysql> create table DemoTable( Score1 int, Score2 int, Score3 int, Score4 int ); Query OK, 0 rows affected (0.50 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(88,76,45,56); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(99,78,87,34); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(34,32,56,98); Query OK, 1 row affected (0.44 sec)
Display all records from the table using select statement &minsu;
mysql> select *from DemoTable;
This will produce the following output −
+--------+--------+--------+--------+ | Score1 | Score2 | Score3 | Score4 | +--------+--------+--------+--------+ | 88 | 76 | 45 | 56 | | 99 | 78 | 87 | 34 | | 34 | 32 | 56 | 98 | +--------+--------+--------+--------+ 3 rows in set (0.00 sec)
Following is the query to find minimum score from four columns of the database −
mysql> select least(Score1,Score2,Score3,Score4) AS MinimumScore from DemoTable;
This will produce the following output −
+--------------+ | MinimumScore | +--------------+ | 45 | | 34 | | 32 | +--------------+ 3 rows in set (0.00 sec)
Advertisements