gpt4 book ai didi

mysql - 根据关系在帮助表中将两个表连接在一起

转载 作者:太空宇宙 更新时间:2023-11-03 11:30:01 24 4
gpt4 key购买 nike

我有两张 table

用户:电话号码,优惠券

客户:customer_id、优惠券

我想创建一个帮助表,根据特定的优惠券将 user 和 customer_id 链接在一起。第三个表将包含三个字段:coupon、phone_number、customer_id,它们应该从这两个表中检索。我试过 Inner Join 但似乎行不通。有人可以帮忙吗?

SELECT customers.customer_id as customer_id, users.phone as 
phone
FROM linked_customers_users
INNER JOIN customers
ON linked_customers_users.customer_id = customers.customer_id
INNER JOIN users
ON linked_customers_users.phone = users.phone

最佳答案

尝试LEFT JOIN:

SELECT customers.customer_id as customer_id, users.phone as 
phone
FROM linked_customers_users
LEFT JOIN customers
ON linked_customers_users.customer_id = customers.customer_id
LEFT JOIN users
ON linked_customers_users.phone = users.phone

关于mysql - 根据关系在帮助表中将两个表连接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50798229/

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