我想获取最后的记录,但显示为升序而不是降序。
SELECT R.cr_id,
R.time,
R.reply,
U.id,
U.username,
U.firstname,
U.lastname,
U.email,
U.image
FROM (HM_customers U, HM_conversation_reply R)
WHERE R.user_id_fk = U.id AND R.c_id_fk = '1'
ORDER BY R.cr_id DESC LIMIT 20
编辑...
我正在使用两张桌子。
答案 0 :(得分:0)
试试这个
SELECT R.cr_id,
R.time,
R.reply,
U.id,
U.username,
U.firstname,
U.lastname,
U.email,
U.image
FROM HM_customers U, HM_conversation_reply R
ON R.user_id_fk = U.id
WHERE R.c_id_fk = '1'
GROUP BY R.cr_id
ORDER BY R.cr_id DESC LIMIT 20
答案 1 :(得分:0)
以下代码为我工作。
SELECT t.cr_id,
t.time,
t.reply,
t.id,
t.username,
t.firstname,
t.lastname,
t.email,
t.image
FROM (
SELECT R.cr_id,
R.time,
R.reply,
U.id,
U.username,
U.firstname,
U.lastname,
U.email,
U.image
FROM (HM_customers U, HM_conversation_reply R)
WHERE R.user_id_fk = U.id AND R.c_id_fk = '1'
ORDER BY R.cr_id DESC
limit 20
) t
ORDER BY t.cr_id ASC
答案 2 :(得分:-1)
SELECT R.cr_id,
R.time,
R.reply,
U.id,
U.username,
U.firstname,
U.lastname,
U.email,
U.image
FROM HM_customers U join HM_conversation_reply R
WHERE R.user_id_fk = U.id AND R.c_id_fk = '1'
ORDER BY R.cr_id DESC LIMIT 20
答案 3 :(得分:-4)
更改
ORDER BY R.cr_id DESC LIMIT 20
到
ORDER BY R.cr_id ASC LIMIT 20