我想运行此查询:
SELECT col1 , col2 , table1.*
FROM
(SELECT table2.col1 as col1 , table2.col2 as col2 , table1.* FROM table1 INNER JOIN table2 ...
UNION
SELECT table3.col1 as col1 , table2.col2 as col2 , table1.* FROM table1 INNER JOIN table2 ...
)order by table1.col1
但我无法运行它,因为我应该将 ( SELECT col1 , col2 , table1.*) 处的 table1.* 替换为 table1 列名称。
最佳答案
您需要为联合查询指定别名。
类似于:
SELECT col1 , col2 , talias.*
FROM
(SELECT table2.col1 as col1 , table2.col2 as col2 , table1.* FROM table1 INNER JOIN table2 ...
UNION
SELECT table3.col1 as col1 , table2.col2 as col2 , table1.* FROM table1 INNER JOIN table2 ...
) as talias order by talias.col1
关于mysql - 如何将 select * 与 union 一起使用? mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24413357/