查询表4的内连接

发布于 2024-08-28 06:50:49 字数 721 浏览 9 评论 0原文

我面临表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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

身边 2024-09-04 06:50:49

在使其更具可读性之后,似乎并没有太大的错误。我删除了括号,因为不需要它们。我还会以相反的方式放置 INNER JOINS,因为正常情况下按此顺序放置它们。

选择列名
从表名1
内连接表名2
ON table_name1.column_name=table_name2.column_name

所以它应该看起来像

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 INSURED.MEMBERSHIPID=MEMBERSHIP.MEMBERSHIPID
INNER JOIN POLICY on POLICY.POLICYNAME=MEMBERSHIP.POLICYNAME
INNER JOIN ORGANIZATION on MEMBERSHIP.ORGANIZATIONID=ORGANIZATION.ORGANIZATIONID
WHERE INSUREDID=427

你需要告诉我们问题是什么。它返回的结果是否与您期望的不同,或者是否因错误而失败。

您还应该告诉我们您正在使用哪个数据库。

您的表结构似乎也有些奇怪。您通常不会将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

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 INSURED.MEMBERSHIPID=MEMBERSHIP.MEMBERSHIPID
INNER JOIN POLICY on POLICY.POLICYNAME=MEMBERSHIP.POLICYNAME
INNER JOIN ORGANIZATION on MEMBERSHIP.ORGANIZATIONID=ORGANIZATION.ORGANIZATIONID
WHERE INSUREDID=427

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.

春花秋月 2024-09-04 06:50:49

INNER JOIN 替换为 LEFT OUTER JOIN

Replace INNER JOIN with LEFT OUTER JOIN.

海之角 2024-09-04 06:50:49

去掉内部连接语句周围的括号。

Get rid of the brackets around your inner join statements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文