Retrieve highest and lowest salary From An Employee Table In MySql
In article we will explain how to write a MySQL query to Retrieve highest and lowest salary from the employees table.
Read Also : MySQL Query To Find The Second Highest Salary
Retrieve highest and lowest salary From An employees Table
First let’s create a simple example of employees table. We will populate this table with id, name, salary and department of employees.
SELECT * FROM employees;
id | name | salary | department |
---|---|---|---|
1 | Tom | 4000 | Technology |
2 | Sam | 6000 | Sales |
3 | Bob | 3000 | Technology |
4 | Alen | 8000 | Technology |
5 | Jack | 12000 | Marketing |
6 | Charlie | 8000 | Human Resources |
7 | Harry | 6000 | Marketing |
8 | Jacob | 4000 | Human Resources |
The following MySQL statement finds the highest and lowest salary From An employees Table:
SELECT MAX(salary), MIN(salary) FROM employees;
MAX(salary) | MIN(salary) |
---|---|
12000 | 3000 |
In above MySQl query we used-
The MySQL MAX function returns the maximum value in a set of values.
The MySQL MIN function returns the minimum value in a set of values.