我想按日期订购2个表,但问题是sql没有同时订购它们。
这是我的查询:
SELECT users_id,CONCAT_WS(' ', users_fname, users_lname)
AS full_name, reply_message, concern_message
FROM tbl_usersinfo AS i
LEFT JOIN tbl_concern AS c
ON c.student_id = i.users_id
LEFT JOIN tbl_reply_concern AS r
ON r.student_id = i.users_id
ORDER BY c.date,r.date
我读到我需要输入ISNULL(c.date,r.date),但它无效。
答案 0 :(得分:1)
尝试ifnull
或coalesce
SELECT users_id,
CONCAT_WS(' ', users_fname, users_lname) AS full_name,
reply_message,
concern_message
FROM tbl_usersinfo AS i
LEFT JOIN tbl_concern AS c
ON c.student_id = i.users_id
LEFT JOIN tbl_reply_concern AS r
ON r.student_id = i.users_id
ORDER BY ifnull(c.date, r.date)
MySQL的等同于ISNULL(在SQL Server中)是IFNULL。在MySQL中,我相信ISNULL只是测试某事物是否为零,并将其评估为0或1。