Search This Blog

Tuesday, April 6, 2010

How to find highest and second highest value of a column in a table

Using below sql query we can find highest and second highest column value of table.
1- Highest
SELECT sal FROM emp e WHERE 1=(SELECT count(*) FROM emp WHERE e.sal <= sal)

2- Second Highest
SELECT sal FROM emp e WHERE 1=(SELECT count(*) FROM emp WHERE e.sal < sal)

2 comments:

  1. Hi Arvind


    It's very nice to see u r blog, we can use for like discussion forum.Can we create group and any one had question then he post his question on blog and any one who knows better answer of this question then he posted his answer.

    ReplyDelete