gpt4 book ai didi

mysql - 如何将 select * 与 union 一起使用? mysql

转载 作者:行者123 更新时间:2023-11-30 00:07:21 25 4
gpt4 key购买 nike

我想运行此查询:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com