Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql query to fetch 3rd lowest value

Tags:

sql

I have a table called employee_salary, having two columns(emp_id, emp_salary) in it.

I have a requirement to fetch 3rd lowest emp_salary from this table. In this case, what should be my query so that i can get the exact value.

like image 628
Kamal Avatar asked Feb 27 '26 12:02

Kamal


2 Answers

I have tested this in Postgres Database. I hope this query work in all type of database. please try this.

SELECT 
  [emp_salary]
FROM [employee_salary]
GROUP BY [emp_salary]
ORDER BY [emp_salary] LIMIT 1 OFFSET 2;
like image 84
Mr. Black Avatar answered Mar 02 '26 15:03

Mr. Black


This may be one solution

select top 1 * from
(
    select top 3 * from
    (
     select distinct  emp_sal from employee order by asc emp_sal
    ) d orderby desc emp_sal
)
like image 42
Pranay Rana Avatar answered Mar 02 '26 15:03

Pranay Rana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!