我有2个与流动列相同的表
id,
timestamp,
country,
data
table 1
正在存储country A
的信息,以及
table 2
正在存储country B
我需要做SELECT from both table ORDER BY timestamp
有人可以用最好和最正确的方式帮助我吗?
由于
答案 0 :(得分:4)
请尝试
(SELECT * FROM `table 1`)
UNION
(SELECT * FROM `table 2`)
ORDER BY timestamp;
答案 1 :(得分:1)
SELECT * FROM tableA
UNION ALL
SELECT * FROM tableB
您需要将ORDER BY
应用于组合(UNION'ed)结果集,因此最终查询将如下所示:
SELECT * FROM (
SELECT * FROM tableA
UNION ALL
SELECT * FROM tableB
) ORDER BY timestamp;
答案 2 :(得分:0)
选择t1.id,t1.timestamp,t1.country,t1.data,t2.id,t2.timestamp,t2.country,t2.data从tableA作为t1,tableB作为t2顺序由t1.timestamp; < / p>