[英]Sql SELECT from 2 table
I have 2 same table with flowing column 我有两个相同的表与流动的列
id,
timestamp,
country,
data
table 1
is storing information for the country A
, and table 2
is storing information for the country B
table 1
存储有关country A
, table 2
存储有关country B
i need to do SELECT from both table ORDER BY timestamp
我需要SELECT from both table ORDER BY timestamp
进行SELECT from both table ORDER BY timestamp
can anybody help me with best and correct way? 有人可以以最佳和正确的方式帮助我吗?
Thanks 谢谢
Please try 请试试
(SELECT * FROM `table 1`)
UNION
(SELECT * FROM `table 2`)
ORDER BY timestamp;
SELECT * FROM tableA
UNION ALL
SELECT * FROM tableB
You need to apply ORDER BY
to the combined (UNION'ed) resultset, so the final query will look like this: 您需要将ORDER BY
应用于合并的(UNION)结果集,因此最终查询将如下所示:
SELECT * FROM (
SELECT * FROM tableA
UNION ALL
SELECT * FROM tableB
) ORDER BY timestamp;
从表A中选择t1.id,t1.timestamp,t1.country,t1.data,t2.id,t2.timestamp,t2.country,t2.data作为t1,tableB作为t2的顺序由t1.timestamp;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.