mysql左键关联_MySQL的:左键删除重复列加入,3个表

我有一个表,使用3个外键到其他表.当我执行左连接时,我会收到重复的列.

MySQL表示,USING语法将减少重复的列,但没有多个键的示例.

鉴于:

mysql> describe recipes;

+------------------+------------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+------------------+------------------+------+-----+---------+-------+

| ID_Recipe | int(11) | NO | PRI | NULL | |

| Recipe_Title | char(64) | NO | | NULL | |

| Difficulty | int(10) unsigned | NO | | NULL | |

| Elegance | int(10) unsigned | NO | | NULL | |

| Quality | int(10) unsigned | NO | | NULL | |

| Kitchen_Hours | int(10) unsigned | NO | | NULL | |

| Kitchen_Minutes | int(10) unsigned | NO | | NULL | |

| Total_Hours | int(10) unsigned | NO | | NULL | |

| Total_Minutes | int(10) unsigned | NO | | NULL | |

| Serving_Quantity | int(10) unsigned | NO | | NULL | |

| Description | varchar(128) | NO | | NULL | |

| ID_Prep_Text | int(11) | YES | | NULL | |

| ID_Picture | int(11) | YES | | NULL | |

| Category | int(10) unsigned | NO | | NULL | |

| ID_Reference | int(11) | YES | | NULL | |

+------------------+------------------+------+-----+---------+-------+

15 rows in set (0.06 sec)

mysql> describe recipe_prep_texts;

+------------------+---------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+------------------+---------------+------+-----+---------+-------+

| ID_Prep_Text | int(11) | NO | PRI | NULL | |

| Preparation_Text | varchar(2048) | NO | | NULL | |

+------------------+---------------+------+-----+---------+-------+

2 rows in set (0.02 sec)

mysql> describe recipe_prep_texts;

+------------------+---------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+------------------+---------------+------+-----+---------+-------+

| ID_Prep_Text | int(11) | NO | PRI | NULL | |

| Preparation_Text | varchar(2048) | NO | | NULL | |

+------------------+---------------+------+-----+---------+-------+

2 rows in set (0.02 sec)

mysql> describe mp_references;

+--------------+---------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+--------------+---------+------+-----+---------+-------+

| ID_Reference | int(11) | NO | PRI | NULL | |

| ID_Title | int(11) | YES | | NULL | |

| ID_Category | int(11) | YES | | NULL | |

+--------------+---------+------+-----+---------+-------+

3 rows in set (0.00 sec)

我的查询语句:

SELECT *

FROM Recipes

LEFT JOIN (Recipe_Prep_Texts, Recipe_Pictures, mp_References)

ON (

Recipe_Prep_Texts.ID_Prep_Text = Recipes.ID_Prep_Text AND

Recipe_Pictures.ID_Picture = Recipes.ID_Picture AND

mp_References.ID_Reference = Recipes.ID_Reference

);

我的目标是从连接中获取一行不含重复列的所有列.我使用MySQL C连接器发送SQL语句并检索结果集.我相信C连接器有重复列名的问题.

那么我应该使用什么是SQL语句语法?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值