MySQL Tutorial
MySql MIN function is used to find the particular column lowest value in the mysql table.
MySql MIN function syntax,
select MIN(column-name) from <table-name>;
Let us see the example to find lowest salary in mysql table 'tblemployee1'.
mysql> select * from tblemployee1; +--------+----------+---------+--------+ | emp_id | emp_name | dept_id | salary | +--------+----------+---------+--------+ | 1 | emp1 | 10 | 10000 | | 2 | emp2 | 11 | 20000 | | 3 | emp3 | 10 | 15000 | | 4 | emp4 | 11 | 12000 | +--------+----------+---------+--------+ 4 rows in set (0.00 sec) mysql> select MIN(salary) from tblemployee1; +-------------+ | MIN(salary) | +-------------+ | 10000 | +-------------+ 1 row in set (0.38 sec)
Let us see the example to find second lowest salary in mysql table 'tblemployee1'.
Using subquery,
mysql> select * from tblemployee1; +--------+----------+---------+--------+ | emp_id | emp_name | dept_id | salary | +--------+----------+---------+--------+ | 1 | emp1 | 10 | 10000 | | 2 | emp2 | 11 | 20000 | | 3 | emp3 | 10 | 15000 | | 4 | emp4 | 11 | 12000 | +--------+----------+---------+--------+ 4 rows in set (0.00 sec) mysql> select MIN(salary) from tblemployee1 where salary not in (select MIN(salary) from tblemployee1); +-------------+ | MIN(salary) | +-------------+ | 12000 | +-------------+ 1 row in set (0.38 sec)
Using Not equals,
mysql> select MIN(salary) from tblemployee1 where salary <> (select MIN(salary) from tblemployee1); +-------------+ | MIN(salary) | +-------------+ | 12000 | +-------------+ 1 row in set (0.00 sec) mysql>
MySQL Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page