开发者

Select ten recent review comments from ten different users

开发者 https://www.devze.com 2023-04-06 23:48 出处:网络
I have two database tables, Users and Review. The User table开发者_JS百科 has a reference key to the Review table.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消