我有 2 个带有流动列的同一张桌子
id,
timestamp,
country,
data
table 1
正在为 存储信息country A
,并且
table 2
正在为 存储信息country B
我需要去做SELECT from both table ORDER BY timestamp
任何人都可以用最好和正确的方法帮助我吗?
谢谢
请试试
(SELECT * FROM `table 1`)
UNION
(SELECT * FROM `table 2`)
ORDER BY timestamp;
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;
选择 t1.id,t1.timestamp,t1.country,t1.data,t2.id,t2.timestamp,t2.country,t2.data from tableA as t1,tableB as t2 order by t1.timestamp;