![](/img/trans.png)
[英]select columns that exist in in table1 and not in table2 where table1 and table2 differ in columns
[英]SQL: I want to select all columns from table1 where columnA in table1 is equal to ColumnB in table2
我有2個表具有共同的列Material:
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中的材料與table2中的材料匹配
在上述情況下,我希望得到此結果,因為表2中存在物料“ ABC”和“ XYZ”:
MG2| ABC| Desc2| 13
MG3| XYZ| Desc3| 9
SELECT * FROM Table1 AS t1
WHERE t1.Material IN
(
SELECT DISTINCT t2.Material
FROM Table2 AS t2
)
SELECT T1.*
FROM TABLE1 AS T1
INNER JOIN TABLE2 AS T2
ON T1.MATERIAL = T2.MATERIAL
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.