I have two database tables, Users
and Review
. The User
table开发者_JS百科 has a reference key to the Review
table.
User table ---------- userid name password email Review Table ------------ reviewid userid comment datetime
I am using mysql database
I want to query 10 recent user review comments without repeating the same user in case where are user have 4 most recent reviews. So in effect the 10 result will be from different users.
How do I do this?
Try
SELECT *, COUNT(*) reviews_no
FROM review
GROUP BY userid
HAVING reviews_no > 4
ORDER BY datetime DESC
LIMIT 10
精彩评论