Ask Question
5 November, 02:28

You have a Microsoft SQL Server 2012 database that contains tables named Customers and Orders. The tables are related by a column named CustomerID. You need to create a query that meets the following requirements: Returns the CustomerName for all customers and the OrderDate for any orders that they have placed. Results must include customers who have not placed any orders. Which Transact-SQL query should you use?

+3
Answers (1)
  1. 5 November, 02:35
    0
    select c. CustomerName, o. OrderDate from Customers c left join Orders o on c. CustomerID=o. CustomerID

    Explanation:

    Since we need also retrieve customers who have not placed any orders, we must use left join while querying CustomerName and OrderDate columns from Customers and Orders table.

    Since CustomerID is the common column of two tables we can use this relation in the query statement.

    We can use alias to represent tables, so that query will became shorter.

    Thus, the statement is:

    select

    c. CustomerName, o. OrderDate

    from Customers c left join Orders o

    on c. CustomerID=o. CustomerID
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “You have a Microsoft SQL Server 2012 database that contains tables named Customers and Orders. The tables are related by a column named ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers