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

sql limit sistinct records

Status
Not open for further replies.

adybih

Technical User
Feb 7, 2006
1
BA
Can someone help me brothers ? I have so one stupid problem.
I have table with two column: city and price. for exemple 20 prices for London and 34 prices for Paris. How can i use sql to select just 5 cheppest prices for each city ? like hear: Thank very much. if someone dont find way to help me I lose my job
 
One way:
SELECT A.city, A.price
FROM yourTable AS A
WHERE A.price IN (SELECT TOP 5 price FROM yourTable WHERE city=A.city ORDER BY 1)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top