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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to return top 10 values in a query

Status
Not open for further replies.

jvanderw

Technical User
Aug 13, 2003
28
US
I am trying to run a query that will be able to list the top 10 values (this is the 10 transactions that occurred the most by percent). I have one query (called transsum) that sums up all of the transactions by transaction type, then I run another query (called trans%) off of transsum that will calculate the transaction percent. I want the query to return only the 10 highest percents. I tried to do an auto number in trans% and then limit the auto number field to 10 or less, but couldn't find a way to do it.
Is there a way to write SQL so that if I have transsum sorted descending according to transaction counts then trans% will only grab the 10 highest transaction counts. Or is there a completely different way to do this?
Thanks in advance,
Josh
 
in your query that has the percentage information try:

SELECT TOP 10 (all your other information)

if you want the highest percentages then "order by DESC" if you want the lowest 10 percentages "order by ASC"
 
Yes, I can tell you exactly how to do it. Look at this sample table:

fruit price
apples $6.00
oranges $2.00
strawberries $1.00
cherries $10.00
pineapple $15.00

Using the query design interface, I created a query that sorted the records by price. Then, I switched to SQL view. I inserted the words "top 3" after the keyword SELECT. I then saved the query. Now the query returned these results:

fruit price
pineapple $15.00
cherries $10.00
apples $6.00

You need to use a similar approach for your project.
 
Thanks to both of you, works like a charm!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top