Pages

Search This Blog

Wednesday, November 14, 2007

Select DISTINCT column together with Non DISTINCT Column

I have a post rating table named Rate, with Column RateID (auto ID), PostID, DateRated

I want the select the 20 latest rated post with no repeated PostID

Below query help me to get the data needed


SELECT TOP 20 PostID, MAX(RateID) AS RateID, MAX(DateRated ) AS DateRated FROM Rate
GROUP BY PostID
ORDER BY RateID DESC, DateRated DESC

No comments: