问题描述:
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
但这里为了现在不工作,这是我得到的结果运行以上查询后
答
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
+1
一个独特的身份证为什么倒投票? –
答
您尚未使用任何聚合函数,因此您的group by
仅返回第1个数据集。有几种方法以解决它
- 删除组,只是如果你想通过我们conversation_id
- 使用聚合函数来排序
+0
我只需要一个结果这就是为什么 – hellosheikh
使用顺序你需要删除'GROUP BY conversation_id' 。 – MrDarkLynx
'ORDER BY DESC LIMIT 1'就是这样。你为什么需要'GROUP BY'? –
你期待/想要发生什么? – Ilion