?
Solved

SELECT/JOIN Correlation Error

Posted on 2008-10-03
6
Medium Priority
?
294 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 600 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 600 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

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