SQL same exposed names

Hi

I get the following error when trying to run the SQL below. I am not sure what this means:

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

SELECT [Orders].[Order ID], [Order Details].[Quantity], [Orders].[Customer ID], [Customers].[First Name], [Customers].[Last Name] FROM [Customers] INNER JOIN [Orders] ON ([Customers].[ID] = [Orders].[Customer ID]), [Orders] INNER JOIN [Order Details] ON ([Orders].[Order ID] = [Order Details].[Order ID])
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Cleaned up, removed an orphan [Orders], and used table aliases.
SELECT o.[Order ID], od.[Quantity], o.[Customer ID], c.[First Name], c.[Last Name] 
FROM Customers c
   JOIN Orders o ON c.[ID] = o.[Customer ID]
   JOIN [Order Details] od ON o.[Order ID] = od.[Order ID]

Open in new window

btw consider renaming the columns with spaces to not use a space, e.g. [Order ID] to OrderID, as that forces you to use square brackets [] around the name in T-SQL, which is one thing to potentially forget and throw an error.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vikas GargBusiness Intelligence DeveloperCommented:
Hi,

I think you have used Orders after inner join

INNER JOIN [Orders] ON ([Customers].[ID] = [Orders].[Customer ID]), [Orders]

is causing error

Please recheck it
0
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks Jim
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks Jim
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.