MySQL union 2表按顺序排列

时间:2015-07-16 14:15:25

标签: mysql select union

我的排序无效,我想对表格数据进行排序1

SELECT session_id
FROM t_table_1
WHERE dateNew BETWEEN '2015-01-01' AND '2015-01-25'
AND session_id NOT IN ((SELECT distinct session_id FROM t_table_2))
GROUP BY session_id
ORDER BY id DESC LIMIT 0, 20
UNION ((SELECT DISTINCT session_id FROM t_table_2 WHERE status = '0'))

不按顺序排序

1 个答案:

答案 0 :(得分:0)

这是否符合您的要求

SELECT * FROM
(SELECT session_id
 FROM t_table_1
 WHERE dateNew BETWEEN '2015-01-01' AND '2015-01-25'
 AND session_id NOT IN ((SELECT distinct session_id FROM t_table_2))
 GROUP BY session_id
 ORDER BY id DESC LIMIT 0, 20) t
UNION ALL
 ((SELECT DISTINCT session_id FROM t_table_2 WHERE status = '0'))