[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQL same exposed names

Posted on 2014-08-20
5
Medium Priority
?
461 Views
Last Modified: 2014-08-20
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])
0
Comment
Question by:Murray Brown
  • 2
  • 2
5 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 40272429
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
 
LVL 15

Expert Comment

by:Vikas Garg
ID: 40272433
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
 

Author Closing Comment

by:Murray Brown
ID: 40272478
Thanks Jim
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40272480
Thanks for the grade.  Good luck with your project.  -Jim
0
 

Author Comment

by:Murray Brown
ID: 40273254
Thanks Jim
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Suggested Courses

873 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