Ask Question

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?

+4
Answers (1)
  1. 11 November, 23:14
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers