Query for getting second highest salary value

Uncategorized 0 Comment 8

1.Using Limit and group by

SELECT sal FROM employee_table WHERE sal = (select sal from employee_table GROUP BY sal ORDER BY sal ASC limit 1, 1)

2.Using joins

SELECT sal from employee_table as t1 where 2=(select count(distinct(t2.sal)) from employee_table as t2 where t1.sal<=t2.sal);

3.with out using limit and group by

select sal from employee_table where sal=(select max(sal) from employee_table where sal<(select max(sal) from employee_table))


Leave a comment

You must be logged in to post a comment.

© 2016 4frienz. Powered By Flowers

Back to Top