我有一个使用此查询的SQL视图:
SELECT dbo.FBAShipmentItems.ShipmentID, dbo.FBAShipmentItems.FNSKU, dbo.FBAShipmentItems.ASIN, dbo.FBAShipmentItems.Merchant,
dbo.FBAShipments.ShipmentName, dbo.FBAShipments.Prep_Type, dbo.FBAShipmentItems.Quantity
FROM dbo.FBAShipmentItems INNER JOIN
dbo.FBAShipments ON dbo.FBAShipmentItems.ShipmentID = dbo.FBAShipments.ShipmentID
问题是,当我在FBAShipmentItems中接近900个项目而在FBAShipments中有51个项目时,它只显示56个结果。如何在我的观点中获得所有900个结果
答案 0 :(得分:2)
使用LEFT JOIN
代替INNER JOIN
:
SELECT
items.ShipmentID,
items.FNSKU,
items.ASIN,
items.Merchant,
shipments.ShipmentName,
shipments.Prep_Type,
items.Quantity
FROM dbo.FBAShipmentItems AS items
LEFT JOIN dbo.FBAShipments AS shipments
ON items.ShipmentID = shipments.ShipmentID
这将返回FBAShipmentItems
中的所有行以及来自FBAShipments
的匹配行(如果有),否则返回NULL表示该表中的所有值。