Home » SQL

SQL Query to find the Nth minimum Salary



Here, we will learn how to find Nth minimum salary of an employee from given table in MySQL?
Submitted by Preeti Jain, on January 02, 2018

Given a table ‘EMPLOYEE’ and we have to find Nth minimum salary of an employee.

TABLE: EMPLOYEE

    ID	NAME	CONTACT	SALARY
    1	PREETI	123456	2000
    2	ARPIT	123789	3000
    3	ADI	147258	5000
    4	APOORV	789632	10000
    5	RIDDHI	148796	20000
    6	REX	148965	30000
    7	WENDY	128659	40000
    8	ANIKET	123489	50000

Case 1: Write a query to find first minimum salary employee from Employee.

mysql> select * from EMPLOYEE where salary = (select min(salary) from EMPLOYEE);

Output/Result

    ID	NAME	CONTACT	SALARY
    1	PREETI	123456	2000

Case 2: Write a query to find second minimum salary employee from Employee.

mysql> select * from EMPLOYEE 
where salary = (select min(salary) from EMPLOYEE 
where salary > (select min(salary) from EMPLOYEE));

Output/Result

    ID	NAME	CONTACT	SALARY
    2	ARPIT	123789	3000

Case 3: Write a query to find third minimum salary employee from Employee.

mysql> select * from EMPLOYEE 
where salary = (select min(salary) from EMPLOYEE 
where salary > (select min(salary) from EMPLOYEE 
where salary > select(min(salary) from EMPLOYEE)));

Output/Result

ID	NAME	CONTACT	SALARY
3	ADI	147258	5000

Case 4: Write a query to find fourth minimum salary employee from Employee.

mysql> select * from EMPLOYEE 
where salary = (select min(salary) from EMPLOYEE 
where salary > (select min(salary) from EMPLOYEE 
where salary > (select(min(salary) from EMPLOYEE 
where salary>(select min(salary) from EMPLOYEE))));





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.




Comments and Discussions





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.