Write a query to get the maximum and minimum salary in the company.
Objective:
Write a SQL query to get the maximum and minimum salary from the employees
table.
Assumed Table: employees
id | name | department | salary | hire_date |
---|---|---|---|---|
1 | John Smith | HR | 50000.00 | 2020-01-15 |
2 | Alice Johnson | Engineering | 75000.00 | 2019-03-22 |
3 | Bob Lee | Sales | 62000.00 | 2021-07-10 |
4 | Mary Jane | Engineering | 80000.00 | 2018-11-05 |
5 | Tom Hardy | Marketing | 55000.00 | 2022-06-01 |
SQL Query to Get Max and Min Salary:
SELECT
MAX(salary) AS max_salary,
MIN(salary) AS min_salary
FROM
employees;
Explanation:
MAX(salary)
→ Finds the highest salary in thesalary
column.MIN(salary)
→ Finds the lowest salary in thesalary
column.AS
→ Gives an alias (column name) to the output for better readability.
Output:
max_salary | min_salary |
---|---|
80000.00 | 50000.00 |
Bonus Tip:
If you want to include the employee name along with the max/min salary, you can use subqueries:
Get Employee(s) with Maximum Salary:
SELECT * FROM employees
WHERE salary = (SELECT MAX(salary) FROM employees);
Get Employee(s) with Minimum Salary:
SELECT * FROM employees
WHERE salary = (SELECT MIN(salary) FROM employees);
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Terms Disclaimer About Us Contact Us
Copyright 2023-2025 © All rights reserved.