我有一些示例数据的表:

Supplier_ID Product_ID  Stock
-----------------------------
1             272          1
1             123          5
1             567          3
1             564          3
2             272          4
2             12           3
2             532          1
3             123          4
3             272          5


我想检查同时具有以下两个产品的供应商:272123,所以结果将是:

Supplier_ID
-----------
1
3

最佳答案

试试这个代码:

SELECT A.Supplier_ID FROM
 (SELECT Supplier_ID FROM Your_Table WHERE Product_ID = 272) AS A
INNER JOIN
 (SELECT Supplier_ID FROM Your_Table WHERE Product_ID = 123) AS B
   ON A.Supplier_ID = B.Supplier_ID

10-06 03:03