当某个列不在第一个表中时,如何使用左连接语句 [英] How do I use left join statements when a certain column is not in the first table

查看:68
本文介绍了当某个列不在第一个表中时,如何使用左连接语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将所有表组合成一个带左连接的大表。但是,因为我的配置文件表在表中没有cemetery_ID,所以join语句不会绑定。但是,我需要cemetery_ID加入cemetery_reference表。



这就是我所拥有的:



I have been trying to combine all tables into a large table with a left join. However, because my profile table does not have a cemetery_ID in the table the join statement will not bind. however, I need the cemetery_ID to join the cemetery_reference table.

here is what I have:

"Select * From profile Left join cemeteries on Profile.ID = cemeteries.Individual_ID left join Cemetery_reference on Cemetery.Cemetery_ID = Cemetery_reference.Cemetery_ID"





我尝试了什么:



尝试使用括号分隔连接,但这不起作用。



What I have tried:

Tried to separate the joins by using parenthesis but this not work.

推荐答案

那是因为Cemeteries表(与Profile共享一个链接)和Cemetery表(链接到Cemetery_reference表)之间,或者公墓和个人资料表。



你可能想要使用墓地(或墓地)表而不是两者,但如果你没有,那就没有关系,那么你需要找一个确实提供关系的表,或者改变你的数据库设计。 (我很想接受后者:你为什么还有两张名字相似的牌桌?)
That's because there is no relation shown between the Cemeteries table (which shares a link with Profile) and the Cemetery table (which links to the Cemetery_reference table), or between the Cemetery and Profile tables.

It's possible you meant to use the Cemeteries (or Cemetery) table throughout instead of both, but if you didn't and there is no relationship, then you need to look for a table which does provide a relationship, or change your DB design. (I'd be tempted to go with the latter: why do you have two tables with such similar names anyway?)


这篇关于当某个列不在第一个表中时,如何使用左连接语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆