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

Top 20 and bottom 20 values in 1 query

Status
Not open for further replies.

gdev

Technical User
Mar 12, 2001
38
Hi

Is there a way to get the top 20 and bottom 20 values in 1 query without using a union query.
If so, please direct.

Thanks
Gwen
 

I think UNION is the way to go, probably the only way.

(UNION not UNION ALL to avoid duplicates if the rows overlap.)

 
Your right
Thanks
 
Consider a query of the Orders table in Northwind with the top 20 and bottom 20 OrderID values:
Code:
SELECT Orders.*
FROM Orders
WHERE Orders.OrderID In (SELECT TOP 20 OrderID FROM Orders ORDER BY OrderID) Or Orders.OrderID In (SELECT TOP 20 OrderID FROM Orders ORDER BY OrderID Desc);

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Perfect!
Love ya
Thanks very very much.


Gwen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top