SQL same exposed names

Posted on 2014-08-20
Last Modified: 2014-08-20

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])
Question by:murbro
    LVL 65

    Accepted Solution

    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.
    LVL 14

    Expert Comment

    by:Vikas Garg

    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

    Author Closing Comment

    Thanks Jim
    LVL 65

    Expert Comment

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

    Author Comment

    Thanks Jim

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
    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 SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now