Solved

Outer Joins on multiple tables

Posted on 2008-06-25
3
1,275 Views
Last Modified: 2008-07-02
I am trying to run a query using MSQuery off a Cache 5.2.3 database, and am having an issue creating an outer join becuase the query requires 3 separate tables.  When I try to change one of the inner joins to an outer join it tells me that I can't have an outer join with three tables.  How can I get around that?  Here is the sql code it is running (I have changed table names, and field names for security purposes)...

SELECT ACCT1.acn1, ACCT1.mbr_1st_nam, Demographics.MMNAM, ACCT1.mbr_lst_nam, Demographics.MNSUF, ACCT1.addr_line1, ACCT1.city, ACCT1.state, ACCT1.zip, ACCT1.mbr_ssn, CCT.Credit_Card_Number
FROM SQLUser.CCT CCT, SQLUser.Demographics Demographics, SQLUser.ACCT1 ACCT1
WHERE Demographics.acn = ACCT1.acn AND CCT.acn = Demographics.acn AND CCT.acn = ACCT1.acn

The question is, how exactly can I create an outer join so that I return ALL accounts from any table?  If I remove the joins wouldn't I just get redundant information?
0
Comment
Question by:COSMTARFCU
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 21867412
try this:

SELECT ACCT1.acn1, ACCT1.mbr_1st_nam, Demographics.MMNAM, ACCT1.mbr_lst_nam, Demographics.MNSUF, ACCT1.addr_line1, ACCT1.city, ACCT1.state, ACCT1.zip, ACCT1.mbr_ssn, CCT.Credit_Card_Number
FROM
SQLUser.CCT CCT
FULL OUTER JOIN SQLUser.Demographics Demographics ON CCT.acn = Demographics.acn
FULL OUTER JOIN SQLUser.ACCT1 ACCT1 ON Demographics.acn = ACCT1.acn AND  AND CCT.acn = ACCT1.acn

0
 

Author Comment

by:COSMTARFCU
ID: 21867531
Thanks for the response.

When I try that (after changing table names back), I get

[SQLCODE: <-23>:<Label is not listed among the applicable tables>]
[Cache Error: <<Syntax?errdone_2%qaqqt>]
[Details: <Prepare>]
[%msg: < SQL ERROR #23: Label 'ACCT1' is not listed among the applicable tables^SELECT ACCT1.acn1 ,>]

Again, I changed the ACCT1 back to the actual name, and verified that I changed everything to how it should be.
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 21867566
try this instead...its really not a good idea to alias you tables w/ the same name as the table:

SELECT a.acn1, a.mbr_1st_nam, d.MMNAM, a.mbr_lst_nam, d.MNSUF, a.addr_line1, a.city, a.state, a.zip, a.mbr_ssn,
c.Credit_Card_Number
FROM
SQLUser.CCT c
FULL OUTER JOIN SQLUser.Demographics d ON c.acn = d.acn
FULL OUTER JOIN SQLUser.ACCT1 a ON d.acn = a.acn AND  AND c.acn = a.acn
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question