我有2个表有一个公共列材料:
Table1
MaterialGroup | Material | MaterialDescription | Revenue
MG1| DEF| Desc1| 12
MG2| ABC| Desc2| 13
MG3| XYZ| Desc3| 9
MG4| IJK| Desc4| 5
Table2
Vendor | VendorSubgroup| Material| Category
KM1| DPPF| ABC| Cat1
KM2| DPPL| XYZ| Cat2
所以,我想从table1中选择table1中的Material与table2中的Material匹配的所有记录
在上面的场景中,我想要这个结果,因为材料“ABC”和“XYZ”出现在表2中:
MG2| ABC| Desc2| 13
MG3| XYZ| Desc3| 9
答案 0 :(得分:2)
SELECT * FROM Table1 AS t1
WHERE t1.Material IN
(
SELECT DISTINCT t2.Material
FROM Table2 AS t2
)
答案 1 :(得分:1)
SELECT T1.*
FROM TABLE1 AS T1
INNER JOIN TABLE2 AS T2
ON T1.MATERIAL = T2.MATERIAL