查询表4的内连接
我面临表4的内连接问题 以下是给定的查询,请参阅&给我解决方案
select INSURED.FNAME + ' ' + INSURED.LNAME AS MNAME
,INSURED.MEMBCODE as MEMBERCODE
,INSURED.POLICYNO AS POLICYNO
,INSURED.POLICYFRMDATE AS POLICYFROMDATE
,INSURED.POLICYTODATE AS POLICYTODATE
, MEMBERSHIP.MRKEXTNAME AS MARKETINGEXECUTIVE
,MEMBERSHIP.EMPLOYEECOUNT AS EMPLOYEECOUNT
,INSURED.CLAIMID AS CLAIMID
,POLICY.POLICYTYPE
,POLICY.COVAMTHOSPITAL as SUMINSURED
,ORGANIZATION.ORGANIZATIONNAME
from ((INSURED
inner join MEMBERSHIP on MEMBERSHIP.MEMBERSHIPID=INSURED.MEMBERSHIPID)
inner join POLICY on MEMBERSHIP.POLICYNAME=POLICY.POLICYNAME)
inner join ORGANIZATION on ORGANIZATION.ORGANIZATIONID=MEMBERSHIP.ORGANIZATIONID
WHERE INSUREDID=427
I'm facing the problem of inner join of table 4
following is query given plz see & give me solution
select INSURED.FNAME + ' ' + INSURED.LNAME AS MNAME
,INSURED.MEMBCODE as MEMBERCODE
,INSURED.POLICYNO AS POLICYNO
,INSURED.POLICYFRMDATE AS POLICYFROMDATE
,INSURED.POLICYTODATE AS POLICYTODATE
, MEMBERSHIP.MRKEXTNAME AS MARKETINGEXECUTIVE
,MEMBERSHIP.EMPLOYEECOUNT AS EMPLOYEECOUNT
,INSURED.CLAIMID AS CLAIMID
,POLICY.POLICYTYPE
,POLICY.COVAMTHOSPITAL as SUMINSURED
,ORGANIZATION.ORGANIZATIONNAME
from ((INSURED
inner join MEMBERSHIP on MEMBERSHIP.MEMBERSHIPID=INSURED.MEMBERSHIPID)
inner join POLICY on MEMBERSHIP.POLICYNAME=POLICY.POLICYNAME)
inner join ORGANIZATION on ORGANIZATION.ORGANIZATIONID=MEMBERSHIP.ORGANIZATIONID
WHERE INSUREDID=427
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在使其更具可读性之后,似乎并没有太大的错误。我删除了括号,因为不需要它们。我还会以相反的方式放置 INNER JOINS,因为正常情况下按此顺序放置它们。
选择列名
从表名1
内连接表名2
ON table_name1.column_name=table_name2.column_name
所以它应该看起来像
你需要告诉我们问题是什么。它返回的结果是否与您期望的不同,或者是否因错误而失败。
您还应该告诉我们您正在使用哪个数据库。
您的表结构似乎也有些奇怪。您通常不会将PolicyName存储在成员资格表中,而是应该链接某种ID字段而不是PolicyName字符串...类似
POLICY.POLICYID=MEMBERSHIP.POLICYID上的INNER JOIN POLICY
之类的东西您对OrganizationID和MEMBERSHIPID的理解是正确的
简而言之,您需要告诉我们更多相关信息。
After making it a bit more readable there doesn't seem to be much wrong. I removed the brackets as they aren't needed. I would also put the INNER JOINS the other way round as its normal to put them in this order.
SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
So it should look something like
You need to tell us what the problem is. Does it return results different to what you are expecting or does it fail with an error.
You should also tell us which database you are using.
Also there appears to be something odd about your table structure. You would not normally store PolicyName in your Membership Table rather you should be linking with ID Fields of some kind rather than PolicyName Strings...Something Like
INNER JOIN POLICY on POLICY.POLICYID=MEMBERSHIP.POLICYID
You got it right for with OrganizationID and MEMBERSHIPID
In short you need to tell us more about it.
将
INNER JOIN
替换为LEFT OUTER JOIN
。Replace
INNER JOIN
withLEFT OUTER JOIN
.去掉内部连接语句周围的括号。
Get rid of the brackets around your inner join statements.