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 selections 1

Status
Not open for further replies.

dcorrea

IS-IT--Management
Aug 15, 2002
22
US
I currently have a table with 5 differnt facilites (A,B,C, D,E). Each facility has 15 different totals. I am needing the top 10 totals for each facility in one query if possible. Any suggestions?

Thanks,

dc
 
Try this:

SELECT facilityid, facility, facilitytotal
FROM yourtablename t
WHERE facilitytotal in (
select TOP 10 facilitytotal
from yourtablename
where facility = t.facility
order by facilitytotal desc)

-VJ
 
Thanks VJ. I tried the code you provided and received the top (max) total for each facility. This is a good start. I am just needing to get the top 10 totals for each facilty within a query (result of 50 entries instead of 5). I believe I followed your scheme correctly. My only questions was the t. that is in the where clause (t.facility). Can you enlighten me on this?

Thanks,

dc
 
the letter "t" is the alias name of the your table.

which means your table and t refer to same table.

when we say that facility=t.facility we are actually just checking the similar occurences of facilities in your table.

-VJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top