如何通过两个表中的联接查询获取最后一个记录组

时间:2018-08-18 19:19:22

标签: mysql database codeigniter

这是我的模态查询

SELECT COUNT(IF(n.status='0',1, NULL)) as counter, n.notify_from, n.notify_to,  n.status, n.notify_text, n.notify_id, n.notify_type, n.notify_time, r.user_name, r.user_image, r.user_gender FROM `notifications` AS n JOIN register r ON n.`notify_from` = r.unique_user_name WHERE n.`notify_to` = 'IzaazG' AND n.`notify_type` = '6' GROUP BY n.`notify_from` ORDER BY n.`notify_id` DESC

从此查询中,我无法从通知表中获取最后一条记录。

1 个答案:

答案 0 :(得分:0)

从功能COUNT中删除IF条件  并尝试使用case语句