Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 Oracle PL/SQL: Show Nth highest value Jump to:  
Category: >> Oracle PL/SQL >> Show Nth highest value Bookmark and Share

<< lastnext >>

Snippet Name: Show Nth highest value

Description: Select and display the Nth highest value from a table.

Comment: (none)

Language: PL/SQL
Highlight Mode: PLSQL
Last Modified: March 02nd, 2009

SELECT LEVEL, MAX('col_name') FROM my_table
WHERE LEVEL = '&n'
CONNECT BY PRIOR ('col_name') > 'col_name')
GROUP BY LEVEL;
 
-- Example :
--
-- Given a table called emp with the following columns:
--   id   number
--   name varchar2(20)
--   sal  number
--
-- For the second highest salary:
 
SELECT LEVEL, MAX(sal) FROM emp
WHERE LEVEL=2
CONNECT BY PRIOR sal > sal
GROUP BY LEVEL
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 101 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?