康卡特和加入

时间:2016-01-21 07:23:10

标签: sql join concat

我正在尝试连接此表并再加入两个表 我的输出应包含以下列:客户全名(名字和姓氏),产品描述,订购数量。

Table Name Customers:
CustomerId
FirstName 
Lastname
City 
State

Table Name: Orders
OrderNo
CustomerId
ProductID
Quantity

Table: Products
ProductID
Description
Quantity

1 个答案:

答案 0 :(得分: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