gpt4 book ai didi

mysql - 将两个 select 语句合并/合并为一个

转载 作者:行者123 更新时间:2023-11-29 02:52:51 25 4
gpt4 key购买 nike

我有下面的 MySQL 语句,它有几个选择语句,其中一个语句对另一个选择返回的所有结果进行选择。只是想知道是否可以将它组合成一个。例如。就像三重连接。

select networks.name as network_name, installations.name as installation_name
from network_installations

join installations on installations.id = network_installations.installation_id

join networks on networks.id = network_installations.network_id

where network_installations.network_id in (
select network_installations.network_id
from network_installations
where network_installations.installation_id = 1
);

注意。我已经完成了 sql 查询,但这是我第一次使用 sql 连接。

最佳答案

为表 network_installations 使用别名:

select networks.name as network_name, installations.name as installation_name
from network_installations ni1
join installations on installations.id = ni1.installation_id
join networks on networks.id = ni1.network_id
join network_installations ni2 on ni2.network_id = ni1.network_id
where ni2.installation_id = 1

关于mysql - 将两个 select 语句合并/合并为一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33859308/

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