I have a review system on my website where users (profiles) can leave reviews for others. This part works fine.
But on my home page i want to get 10 of the latest reviews BUT i don't want to duplicate any users/profiles (i.e if a user has 2 reviews i only want the most recent)
Adding DISTINCT does not do this as all reviews/rows are unique. (i do add DISTINCT though as some users submit duplicate reviews...)
I have tried GROUP BY ProfileID but this does not necessarily return the most recent review and i can not work out how to do this. (GROUP BY kind of has the desired effect, but i think may be mixing up the data and is not getting the results in date order)
The below (simplified) SQL is what i currently have, but this brings back more than 1 review per user (if they have more than 1)
SELECT DISTINCT LEFT(r.ReviewText, 100) as Review, r.ReviewRating, r.ReviewDate,
p.ProfileName, p.Location, p.ProfileID,
((date_format(now(),'%Y') - date_format(p.DateOfBirth,'%Y')) - (date_format(now(),'00-%m-%d') < date_format(p.DateOfBirth,'00-%m-%d'))) AS Age
FROM tReview r
INNER JOIN tProfiles p ON p.ProfileID = r.tProfiles_ProfileID
WHERE r.ReviewWithdrawn = 0
AND r.ReviewEnabled = 1
AND p.Enabled = 1
ORDER BY r.ReviewDate DESC
LIMIT 10
Any ideas (without filtering in php) as to how i can retrieve 10 results, in date order but only including each user once (so if the user has 2 reviews only the most recent will be returned)?