SQL Recipes (Beta II)
A FREE cookbook for SQL queries and examples
Register FAQ Search Today's Posts Mark Forums Read

SQL - Questions and Answers Have a SQL question? Post it here. First do a search to see if someone hasn't already answered it.

Go Back   SQL Recipes a FREE cookbook of SQL queries and examples > SQL queries and examples > SQL - Questions and Answers

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
  #1 (permalink)  
Old 03-12-2007, 09:17 PM
Anoj biradar
 
Posts: n/a
Default SQL 92 dialect question:

how to find out the 4th highest value from the column?


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Edit/Delete Message Reply With Quote

ANSWER(S):

  #2 (permalink)  
Old 03-25-2007, 07:58 PM
Y.Michael Holding
 
Posts: n/a
Default Oracle answer. Re: how to find out the 4th highest value from the column?

SELECT  ROWNUM AS RANK,D.SALARY
FROM (SELECT MAX(SALARY) AS SALARY
              FROM EMPLOYEES
              ORDER BY SALARY DESC) D
WHERE ROWNUM<=4
MINUS
SELECT  ROWNUM AS RANK,D.SALARY
FROM (SELECT MAX(SALARY) AS SALARY
              FROM EMPLOYEES
              ORDER BY SALARY DESC) D
WHERE ROWNUM<=3
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Edit/Delete Message Reply With Quote
  #3 (permalink)  
Old 12-05-2007, 03:46 AM
Unregistered
 
Posts: n/a
Lightbulb ANY answer. Re: how to find out the 4th highest value from the column?

You can do the same with

select min(sal) from (select sal from emp where sal is not NULL order by sal desc) where rownum<=&rownum;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Edit/Delete Message Reply With Quote
  #4 (permalink)  
Old 12-05-2007, 03:54 AM
deepak garg deepak garg is offline
Junior Member
 
Join Date: Dec 2007
Posts: 6
deepak garg is on a distinguished road
Lightbulb ANY answer. Re: how to find out the 4th highest value from the column?

You can calculate the 2,3,4 or the whichever highest value of a column you want to retrive:


select min(sal) from (select sal from emp where sal is not NULL order by sal desc) where rownum<=&rownum;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-21-2008, 07:24 AM
Unregistered
 
Posts: n/a
Default ANY answer. Re: how to find out the 4th highest value from the column?

U need antivirus?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Edit/Delete Message Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Moderation Tools:


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find second highest value of a column in a table? ruby SQL - Questions and Answers 23 05-07-2008 05:51 AM
How to find second highest value of a column in a table? | SQL? jaheer SQL - Questions and Answers 10 07-24-2007 11:07 AM
how to find third highest record from table? davinder singh SQL - Questions and Answers 3 12-19-2006 11:57 AM


All times are GMT. The time now is 07:23 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
Copyright (c) 2006-2007 SQL Recipes

1 2 3 4 5 6 7