2016-01-21 69 views
0

我想連接此表並加入兩個表。
我的輸出應該包含列:客戶全名(名和姓),產品描述,數量有序。Concat和加入

Table Name Customers: 
CustomerId 
FirstName 
Lastname 
City 
State 

Table Name: Orders 
OrderNo 
CustomerId 
ProductID 
Quantity 

Table: Products 
ProductID 
Description 
Quantity 

回答

0

假設沒有客戶ID或產品ID可以爲null這樣內部連接。

SELECT C.FirstName + ' ' + C.LastName AS [FullName], 
     P.Description AS [ProductDescription], 
     O.Quantity AS [QuantityOrdered] 
    FROM Orders O 
    JOIN Customers C 
    ON C.CustomerId = O.CustomerId 
    JOIN Products P 
    ON P.ProductId = O.ProductId