如何在超过3个表上编写内部连接的选择查询 [英] How Do I Write Select Query Of Inner Join On More Than 3 Tables

查看:58
本文介绍了如何在超过3个表上编写内部连接的选择查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的查询,但没有显示任何结果。请帮帮我。

Following is my query which is not displaying any result. Please help me out.

select * from tblPersonalDetails Inner Join tblFamilyDetails on tblPersonalDetails.Email=tblFamilyDetails.Email
Inner Join tblImageDetails on tblPersonalDetails.Email=tblImageDetails.Email
Inner Join tblEducationalDetails on tblPersonalDetails.Email=tblEducationalDetails.Email
Inner Join tblAcademicDetails on tblPersonalDetails.Email=tblAcademicDetails.Email
Inner Join tblWorkExpDetails on tblPersonalDetails.Email=tblWorkExpDetails.Email
Inner Join tblReferenceDetails on tblPersonalDetails.Email=tblReferenceDetails.Email
Inner Join tblDeclarationDetails on tblPersonalDetails.Email=tblDeclarationDetails.Email where (tblPersonalDetails.FirstName like '%' + @search + '%' )

推荐答案

如评论中所述,您可以将INNER更改为LEFT并查看哪个连接导致所有内容失效。



但是,你不想要只是改变从INNER到LEFT的所有内容而不了解你在做什么。



当你使用INNER加入一个表时,这意味着必须有匹配。因此,例如,如果你INNER JOIN tblReferenceDetails并且tblReferenceDetails中没有匹配的记录,那么你将得不到任何结果。这可能就是你想要的。或者,您可能不关心tblReferenceDetails中没有匹配的记录,在这种情况下,您使用LEFT连接。如果有匹配的记录,你可以拉它的列,否则它们将是NULL。



所以,你需要决定每个JOIN使用正确的类型,不要不要盲目地将INNER改为LEFT。
As mentioned in the comments, you can change your INNER to LEFT and see which join is causing everything to fall out.

However, you don't want to just change everything from INNER to LEFT without understanding what you are doing.

When you join a table using INNER it means that there must be a match. So, for example, if you INNER JOIN tblReferenceDetails and there is no matching record in tblReferenceDetails then you will get no results. This may be what you want. Or, you may not care that there is no matching record in tblReferenceDetails and in that case you use a LEFT join. If there is a matching record, you can pull it's columns otherwise they will be NULL.

So, you need to decide for each JOIN to use the correct type, don't just change INNER to LEFT blindly.


我会在那里取出WHERE子句,看看你的查询是否带回了什么。如果你得到很多记录,我会把注意力集中在WHERE子句上,并在WHERE子句中使用返回项。
I would take off there WHERE clause and see if your query brings get anything back. If you get a lot of records back, I'd then focus my attention to the WHERE clause and use returns items in your WHERE clause.


这篇关于如何在超过3个表上编写内部连接的选择查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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