0

I need some help with a MySql Query. My existing query returns all rows which have 100001 as the query_id, sorted by priceperadult ASC.

However, I want it to only return the best rate per hotel, so need to add to the statement so only one rate per hotel shows, whats the best way to achieve this?

SELECT * FROM `search_results` WHERE `query_id` = '100001' ORDER BY `priceperadult` ASC

Sample Data

query_id, priceperadult, hotel_name

100001, 100, Hotel 1

100001, 200, Hotel 1

100001, 100, Hotel 2

100001, 200, Hotel 2

1 Answer 1

1

Sounds like you're looking to use min():

SELECT query_id, MIN(priceperadult), hotel_name
FROM search_results 
WHERE query_id = '100001' 
GROUP BY query_id, hotel_name
Sign up to request clarification or add additional context in comments.

1 Comment

Thats great thanks for answer. But how do i then sort the list by MIN(priceperadult) in ASC fashion? i.e. lowest rate of all hotels first?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.