我有一个查询
SELECT s.*
, g.*
from tbl_section1 as s
, tbl_game as g
LEFT
JOIN tbl_game_visit_count AS gvc
ON g.game_id = gvc.game_id
where s.category_id = g.game_id
ORDER
BY g.udate DESC
, gvc.visit_count DESC
效果很好。
但是我想获取g.udate
排序的第一个记录,然后获取gvc.visit_count
排序的其余记录。
使用mysql查询可以吗?
谢谢。
答案 0 :(得分:0)
可以在两个带有UNION
和{的查询之间使用UNION ALL
(不是ORDER BY
,因为我们不想重复行)括号内的{1}}子句
LIMIT
P.S。由于您的原始查询,我为SELECT q.*
FROM
(
SELECT s.*, g.*
FROM tbl_section1 as s
INNER JOIN tbl_game as g ON s.category_id = g.game_id
LEFT JOIN tbl_game_visit_count AS gvc ON g.game_id = gvc.game_id
ORDER BY g.udate DESC
LIMIT 1
) q
UNION
SELECT s.*, g.*
FROM tbl_section1 as s
INNER JOIN tbl_game as g ON s.category_id = g.game_id
LEFT JOIN tbl_game_visit_count AS gvc ON g.game_id = gvc.game_id
ORDER BY gvc.visit_count DESC;
保留了DESC
个选项,如果要定期升序排序,可以删除它们。