Solved

SELECT/JOIN Correlation Error

Posted on 2008-10-03
6
273 Views
Last Modified: 2012-05-05
Here's the code:

SELECT armast.fcinvoice, armast.fcstatus, armast.flisprint, aritem.fitem,
  aritem.fpartno, armast.fnumber, armast.fcsource, armast.fsono,
  armast.finvtype, shmast.fshipno, shmast.fcstate
   FROM armast, aritem, shmast
LEFT JOIN shmast on armast.fnumber = shmast.fshipno
WHERE Armast.fcinvoice = Aritem.fcinvoice
AND Armast.fnumber = shmast.fshipno

Here's the error message:

The objects "shmast" and "shmast" in the FROM clause have the same exposed names. Use correlation names to distinguish them.

I looked at some answers on this error on this site, but am not having much luck getting my error resolved. Obviously, I'm not using alias names the right way when I try using them. How do I fix this one?

0
Comment
Question by:glennes
  • 4
6 Comments
 
LVL 7

Accepted Solution

by:
Norush earned 150 total points
ID: 22636091
Try with this
SELECT armast.fcinvoice, armast.fcstatus, armast.flisprint, aritem.fitem,

  aritem.fpartno, armast.fnumber, armast.fcsource, armast.fsono, 

  armast.finvtype, shmast.fshipno, shmast.fcstate 

   FROM armast, aritem

LEFT JOIN shmast on armast.fnumber = shmast.fshipno

WHERE Armast.fcinvoice = Aritem.fcinvoice

AND Armast.fnumber = shmast.fshipno

Open in new window

0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 150 total points
ID: 22636102
Does that table need to be in your query twice for some reason?

armast.fnumber = shmast.fshipno
AND Armast.fnumber = shmast.fshipno

You seem to be joining the same way, so it going to be same record from same table twice.

Anyway, if you need this, you would do:

FROM shmast s1 LEFT JOIN shmast s2
ON s1.fshipno = s2.fshipno

For example.
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22636110
There was a lot of redundancy in the query, so I suspect you may have had a copy and paste mishap.  Happens all the time... Try looking at recreating the query cleanly.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22636136
For example, did you mean something like this.  Think it is a better idea to spell out what kind of join to each table personally.
SELECT  armast.fcinvoice, 

		armast.fcstatus, 

		armast.flisprint, 

		aritem.fitem,

		aritem.fpartno, 

		armast.fnumber, 

		armast.fcsource, 

		armast.fsono, 

		armast.finvtype, 

		shmast.fshipno, 

		shmast.fcstate 

FROM (armast INNER JOIN aritem ON Armast.fcinvoice = Aritem.fcinvoice)

LEFT JOIN shmast ON armast.fnumber = shmast.fshipno

Open in new window

0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 22636144
Norush, just saw your post.  Think you saw the same thing that the shmast table was duplicated and taking out will fix unless glennes needed two instances for some reason.
0
 

Author Closing Comment

by:glennes
ID: 31502853
Thanks, guys. I think it's time to go on home for the week. Clearly, the company isn't getting the intelligence from me that they're paying for today!
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now