How to SELECT DISTINCT Info with TOP 1 Info and an Order By FROM the Top 1 Info

Posted by Erin Taylor on Stack Overflow See other posts from Stack Overflow or by Erin Taylor
Published on 2010-06-03T21:53:32Z Indexed on 2010/06/03 21:54 UTC
Read the original article Hit count: 243

Filed under:
|
|
|

I have 2 tables, that look like:

CustomerInfo(CustomterID, CustomerName) CustomerReviews(ReviewID, CustomerID, Review, Score)

I want to search reviews for a string and return CustomerInfo.CustomerID and CustomerInfo.CustomerName. However, I only want to show distinct CustomerID and CustomerName along with just one of their CustomerReviews.Reviews and CustomerReviews.Score. I also want to order by the CustomerReviews.Score.

I can't figure out how to do this, since a customer can leave multiple reviews, but I only want a list of customers with their highest scored review.

Any ideas?

© Stack Overflow or respective owner

Related posts about sql

Related posts about server