Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Performing Top-N Analysis

apollon27Jul 9 2007 — edited Jul 9 2007
An Oracle University Material in Sql Says

The high-level structure of a Top-N analysis query is:

SELECT [column_list], ROWNUM
FROM (SELECT [column_list]
FROM table
ORDER BY Top-N_column)
WHERE ROWNUM <= N;

For example to display the top three earner names and salaries from the EMPLOYEES table:

SELECT ROWNUM as RANK, last_name, salary
FROM (SELECT last_name,salary FROM employees
ORDER BY salary DESC)
WHERE ROWNUM <= 3;
--------------------------------------------------

My question is

If, instead of this query, I write

1)

SELECT ROWNUM as RANK, last_name, salary
FROM employees
WHERE ROWNUM <= 3
ORDER BY salary DESC

or

2)
SELECT ROWNUM as RANK, last_name, salary
FROM ( SELECT last_name,salary
FROM employees
WHERE ROWNUM <= 3
ORDER BY salary DESC
)


is any difference?

The results in schema hr are the same.............


Thank you
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 6 2007
Added on Jul 9 2007
2 comments
551 views