2

我有 2 个带有流动列的同一张桌子

id,
timestamp,
country,
data

table 1正在为 存储信息country A,并且 table 2正在为 存储信息country B

我需要去做SELECT from both table ORDER BY timestamp

任何人都可以用最好和正确的方法帮助我吗?

谢谢

4

3 回答 3

4

请试试

(SELECT * FROM `table 1`)
UNION
(SELECT * FROM `table 2`)
ORDER BY timestamp;
于 2012-09-15T16:54:23.133 回答
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;
于 2012-09-15T16:53:27.770 回答
0

选择 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;

于 2012-09-15T17:15:40.667 回答