我有两个表作为A和B
表A是
OrderID productCode Qty EXT AorderID
1 aa1 2 1 001
1 aa2 5 2 001
2 bb1 3 1 002
表B是
OrderID BProductCode BQty BExt
1 bbcc 7 1
1 ccdd 8 2
1 eeee 1 3
我想得到这样的结果......
AorderID OrderID productCode Qty Ext OrderID BProductCode BQty BExt
001 1 aa1 2 1 1 bbcc 7 1
001 1 aa2 5 2 1 ccdd 8 2
NULL NULL NULL NULL NULL 1 eeee 1 3
002 2 bb1 3 1 NULL NULL NULL NULL
我尝试选择这样,
Select A.orderID, A.productCode, A.qty , A.ext ,A.AorderID, B.OrderId , B.ProductCode , B.BQty , B.Ext A left outer join B on A.orderID = B.OrderID
答案 0 :(得分:2)
你应该做一个完整的外部加入
SELECT *
FROM TableA a
FULL OUTER JOIN TableB b
ON a.EXT = b.BExt
AND a.OrderID = b.OrderID