gpt4 book ai didi

mysql - 是否可以使用子查询但不使用 JOIN 来编写以下查询?

转载 作者:行者123 更新时间:2023-11-29 16:09:28 25 4
gpt4 key购买 nike

如果可以在没有连接的情况下编写以下代码,我会遇到麻烦吗?如果可能的话,任何人都可以帮助解释和编写没有它的代码吗?

SELECT DISTINCT CONCAT(first_name, ' ', last_name) AS customer_name,
state AS customer_state
FROM customers c JOIN addresses a
ON c.customer_id = a.customer_id
ORDER BY last_name, first_name

最佳答案

给你:

SELECT DISTINCT 
CONCAT(c.first_name, ' ', c.last_name) AS customer_name,
(SELECT a.state FROM addresses a WHERE a.customer_id=c.customer_id ) AS customer_state
FROM customers c
ORDER BY c.last_name, c.first_name

关于mysql - 是否可以使用子查询但不使用 JOIN 来编写以下查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55400030/

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