我想运行此查询:

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


但是我无法运行它,因为我应该将table1。*(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 *? MySQL的,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24413357/

10-16 18:48