Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 基于关系将两个表连接在一个辅助表中_Mysql - Fatal编程技术网

Mysql 基于关系将两个表连接在一个辅助表中

Mysql 基于关系将两个表连接在一个辅助表中,mysql,Mysql,我有两张桌子 用户:电话号码、优惠券 客户:客户id,优惠券 我想创建一个帮助表,根据特定优惠券将用户和客户id链接在一起。第三个表将有三个字段:优惠券、电话号码、客户id,应该从这两个表中检索。我尝试了内部连接,但似乎没有效果。有人能帮忙吗 SELECT customers.customer_id as customer_id, users.phone as phone FROM linked_customers_users INNER JOIN customers ON linked_c

我有两张桌子

用户:电话号码、优惠券

客户:客户id,优惠券

我想创建一个帮助表,根据特定优惠券将用户和客户id链接在一起。第三个表将有三个字段:优惠券、电话号码、客户id,应该从这两个表中检索。我尝试了内部连接,但似乎没有效果。有人能帮忙吗

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

尝试左连接:

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

尝试左连接:

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。您始终可以尝试模拟完整的外部联接(注意,如果您有重复项,这将删除它们):


正如评论员指出的那样,很抱歉您正在使用mysql。您始终可以尝试模拟完整的外部联接(注意,如果您有重复项,这将删除它们):


这实际上并不存在,对吗
linked\u customers\u users
我很困惑,你一开始说的是两个表。@SQLChao这是我创建的第三个表,
linked\u customers\u users
中真的有数据吗?或者您需要插入到中吗参见:这实际上并不存在,对吗
linked\u customers\u users
我很困惑,你一开始说的是两个表。@SQLChao这是我创建的第三个表,
linked\u customers\u users
中真的有数据吗?或者您需要插入到中吗请参见:不,不会,因为MySQL不支持
完全外部连接
不,不会,因为MySQL不支持
完全外部连接