Q
Problem solve Get help with specific problems with your technologies, process and projects.

Selecting a row from an EMP table where ID is in ASC or DESC

How can I select a row from an EMP table where the EMP ID (of the second row) is either in ASC or DESC?
Have a look at the SQL documentation for the RANK function. The RANK function determines the ranking of a row within a specific group of values. To use the RANK function to find the second highest salary in the EMP table, use a query similar to the following
SELECT e.empno, e.name,e.sal
FROM (SELECT empno, name, sal, 
      RANK() OVER (PARTITION BY salary DESC) "RANKING"
      FROM emp ) e
WHERE e.ranking = 2;

Dig Deeper on Oracle database design and architecture

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close