如何合并 MySQL 个表

How To Combine MySQL Tables

我有一个名为 'mylist' 的数据库。其中的表以 'list1' 'list2' 'list3' 的形式存在。所有表都包含相同的结构和列名,但数据不同。

如果我必须 select 所有表中的所有数据,那么我应该 运行 什么查询?

尝试在所有行中使用 UNION 来获取如下所示的所有行:

SELECT output.mycol1, output.mycol2
FROM
(SELECT list1.mycol1, list1.mycol2
FROM list1
UNION
SELECT list2.mycol1, list2.mycol2
FROM list2
UNION
SELECT list3.mycol1, list3.mycol2
FROM list3) AS "output"
ORDER BY output.mycol1