Solved

SELECT/JOIN Correlation Error

Posted on 2008-10-03
6
282 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

820 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