Php GROUPBy和ORDER不一起工作

Php GROUPBy和ORDER不一起工作,php,mysql,Php,Mysql,我有这样的记录 这是我的问题 SELECT `Chat`.`id`, `Chat`.`sender_id`, `Chat`.`receiver_id`, `Chat`.`message`, `Chat`.`datetime`, `Chat`.`converstation_id` FROM `gopher`.`chat` AS `Chat` WHERE ((`Chat`.`s

我有这样的记录

这是我的问题

SELECT   `Chat`.`id`, 
         `Chat`.`sender_id`, 
         `Chat`.`receiver_id`, 
         `Chat`.`message`, 
         `Chat`.`datetime`, 
         `Chat`.`converstation_id` 
FROM     `gopher`.`chat` AS `Chat` 
WHERE    ((`Chat`.`sender_id` = 10) 
OR       (`Chat`.`receiver_id` = 10)) 
GROUP BY converstation_id 
ORDER BY `Chat`.`id` DESC
但是这里的order现在不起作用,这是我在运行上述查询后得到的结果


您没有使用任何聚合函数,因此您的
分组依据仅返回第一个数据集。有几种方法可以解决这个问题

  • 如果您想按对话id排序,请删除group by并使用order by
  • 使用聚合函数

  • 您需要删除
    按对话分组\u id
    按描述顺序限制1
    仅此而已。为什么需要
    GROUP BY
    ?您期望/希望发生什么?您有一个GROUP BY子句,但没有聚合函数。糟糕。你到底想做什么?我只需要一个结果这就是为什么
    SELECT   `Chat`.`id`, 
             `Chat`.`sender_id`, 
             `Chat`.`receiver_id`, 
             `Chat`.`message`, 
             `Chat`.`datetime`, 
             `Chat`.`converstation_id` 
    FROM `gopher`.`chat` AS `Chat` 
    WHERE ((`Chat`.`sender_id` = 10) OR (`Chat`.`receiver_id` = 10))
    GROUP BY converstation_id
    ORDER BY `Chat`.`id` DESC LIMIT 0,1