SQL - 查询3个表时重复

时间:2016-10-19 19:28:00

标签: sql

我有一个非常简单的查询,可以从3个表中提取数据。我决定使用From和Where子句来选择我想要的而不是Join,但是当我运行查询时它会提取重复数据。 DISTINCT也尝试了,但它仍然提取重复数据。

这是查询 -

SELECT 
   IV00101.ITEMNMBR, 
   IV00101.ITEMDESC, 
   ItmPrice.STNDCOST, 
   ItmPrice.DS_Margin, 
   IV00101.CURRCOST, 
   IV00102.LSORDQTY, 
   IV00102.LSRCPTDT, 
   ItmPrice.MODIFDT, 
   ItmPrice.MDFUSRID
FROM 
   DSLLC.dbo.IV00101 IV00101, 
   DSLLC.dbo.IV00102 IV00102, 
   DSLLC.dbo.ItmPrice ItmPrice
WHERE 
   IV00101.ITEMNMBR = IV00102.ITEMNMBR AND 
   IV00101.ITEMNMBR = ItmPrice.ITEMNMBR AND 
   IV00102.ITEMNMBR = ItmPrice.ITEMNMBR 
ORDER BY 
   IV00101.ITEMNMBR

可以看到一小部分结果样本here

1 个答案:

答案 0 :(得分:0)

试试这个:WHERE IV00101.ITEMNMBR = IV00102.ITEMNMBR和IV00102.ITEMNMBR = ItmPrice.ITEMNMBR group by IV00101.ITEMNMBR ORDER BY IV00101.ITEMNMBR