Need Help with SQL statement
Hi Guys!
I have two tables, one with store information and one with reviews of the store. The have each have a foreign key (idstore) to connect them.
In the reviews table, I have an overall_ratings field.
Reviews
-------------------------------------------------------
storeid | overall_rating | MallId | Reviewerid | Comments |DateofReview
-------------------------------------------------------
StoreInfo
-----------------------------------
storeid | stroename| hours
-----------------------------------
Now the tricky part is that I want to grab the latest store review information(from the table reviews) and the storename (from the StoreInfo table) for the stores that have the top 10 (highest) averaged reviews.
So in other words, I want to retreive the last review for the store that is in the top ten for the averaged overall_ratings.
I am using asp.net so I can store info in an array if neccessary. I can come up with parts of this, but the real logic is escaping me.
Thanks in Advance.
Bebandit
Re: Need Help with SQL statement
Maybe something like this:
Code:
SELECT TOP 1(*) FROM Reviews r
INNER JOIN StoreInfo s ON r.StoreID=s.StoreID
WHERE r.StoreID IN (SELECT TOP 10(StoreID) FROM Reviews ORDER BY overall_rating DESC)
ORDER BY DateofReview DESC