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!

Top 10 selection

Status
Not open for further replies.

dcorrea

IS-IT--Management
Aug 15, 2002
22
US
I have the following script:

SELECT t1.*
FROM [MyTable] t1
WHERE t1.TOTAL In (select top 10 t2.TOTAL from [MyTable] t2 where t2.FACILITY = t1.FACILITY);

which provides me with the top ten list of each facility, but not of their totals, but rather their id.

My table is as such

ID FACILITY TOTAL
1 A 100
2 A 102
3 A 97
. . .
. . .
205 E 115
206 E 77

I am needing to retreive the top 10 (greatest #s) totals for each facility on one query. Any suggestions?

Thanks,

dc
 
Try this:

SELECT t1.*
FROM [MyTable] t1
WHERE t1.TOTAL In (select top 10 t2.TOTAL from [MyTable] t2 where t2.FACILITY = t1.FACILITY ORDER BY t2.TOTAL DESC);

VJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top