Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL: How can i get the 10 greatest values.

Status
Not open for further replies.

erwan

Programmer
Aug 24, 2000
19
FR
In sql, i want to get only 10 gretest values on a table .

I try with ROWNUM with " where rownum > count(*) -10 but the "order by" is made after the rownum and the result is false.

how can i do that.
thank you!

 
In Oracle use a subquery.

From the Oracle course:

select ename, sal
from emp e
where 10 >
(select count(*)
from emp
where e.sal < sal)
order by e.sal

In SQLServer use:
select TOP 10 ename, sal
from emp
order by sal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top