2016-07-21 8 views
0
select Products.SKU, Products.MPN, Products.Manufacturer, dpi.DLRcost, dpi.msrp, dpi.Quantity, pu.UnitofMeasure, pu.ActualWeight, pu.ShipWeight,  pu.Length, pu.Width, pu.Height 
from 
(select PartNumber as SKU, MPN, Manufacturer 
from ActiveProducts 
union select SKU, MFP, Brand 
from ActiveItems 
union select SKU, mfr_part_number, manufacturer 
from AllProductsCombined 
) as Products, DealerPriceInventory dpi, PriceUpdate pu 
where Products.sku=dpi.sku AND dpi.sku=pu.SKU 

すべてのスキューが正しい表にないため、上記のクエリの結果を別の表に結合して残したいと考えています。この声明の中のすべてのテーブルに内面が加わらなければ、これを達成するための方法はありますか?where節を使用して結合しているときに内部結合を行うにはどうすればよいですか?

答えて

1

"新しい" ANSI構文が1992年に導入されたので、クエリで自由に使用できます。

...from (...) as Products 
    left join DealerPriceInventory dpi on Products.sku=dpi.sku 
    left join PriceUpdate pu on dpi.sku=pu.SKU 
where <some other conditions> 
+0

クールおかげで、私はそれを試してみますよ。 –

+0

この返信に感謝します。私は基本的にこれを前にやっていましたが、それを凝縮したいだけでした。私が理解していないことは、dpiをプロダクトに左結合し、次にdpiからpuにする方法です。どのように何かを残していないのですか?あなたはdpi/productsからの結果に参加してpriceupdateしたいと思わないでしょうか? –

+0

定義によって 'left join'は、**すべての**行を左のテーブルから返し、一致する行を右から返します。一致しない行は「ヌル」値である。 –

0

これは私が行く方法です:

with Products as (select PartNumber as SKU, MPN, Manufacturer 
from ActiveProducts 
union select SKU, MFP, Brand 
from ActiveItems 
union select SKU, mfr_part_number, manufacturer 
from AllProductsCombined), 
NewTable as (select NewColumn,Sku1 from NewTable) 

select Products.SKU, Products.MPN, Products.Manufacturer, dpi.DLRcost, 
dpi.msrp, dpi.Quantity, pu.UnitofMeasure, pu.ActualWeight, pu.ShipWeight, 
pu.Length, pu.Width, pu.Height, NewTable.NewColumn from Products 
left join DealerPriceInventory dpi on Products.sku=dpi.sku 
left join PriceUpdate pu on dpi.sku=pu.SKU 
left join NewTable on Products.sku=NewTable.sku1 
.... 
関連する問題