MYsql查询错误通过不工作加入组

时间:2017-02-27 13:43:29

标签: php mysql sql-order-by grouping

Table -1 : Comment id, comment,user_id,comment Date
Table -2: Users id, user_name, full_name, password  

现在我想获得最后评论的用户详细记录

像  查询是:

 select c.*, 
   (select user_name 
    from users 
    where id = c.user_id
   ) as user_name, 
   (select full_name 
    from users 
    where id = c.user_id
   ) as full_name 
from comment as c, users as u 
group by c.user_id 
order by comment_date DESC

2 个答案:

答案 0 :(得分:1)

async_read_some

应该有效

答案 1 :(得分:0)

这是您的查询

select users.* from users inner join comments on 
users.user_id =  comments.user_id 
order by comments.comment_date desc limit 1

另一种方法

select * from users where user_id = 
(select user_id from comments order by comment_date desc limit 1)