Solved

SELECT/JOIN Correlation Error

Posted on 2008-10-03
6
288 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:Glenn Stearns
[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
  • 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 60

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 60

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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 60

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 60

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:Glenn Stearns
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

729 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