2014-04-14 41 views
0

我有以下的問題,我想從feature_values表中選擇的product_id其中variant_id等於多個值查詢以多個值爲基礎找到具有多個值的第二列的ID?

我有這個

SELECT product_id FROM feature_values WHERE variant_id = '162' AND variant_id = '11819' 

以上的回報沒有結果

以下兩個查詢返回product_id

SELECT product_id FROM feature_values WHERE variant_id = '162' 

,這

SELECT product_id FROM feature_values WHERE variant_id = '11819' 

表例如數據

Feature ID, Product ID, Variant ID, Value 
     92,  565,  11815 
     69,  565,  162 
     92,  566,  11819 
     69,  566,  162 
+1

我認爲你正在尋找'或'而不是'和' –

回答

1

嘗試這些了,是你正在尋找沒有什麼,邏輯思維變異ID可以是一方或另一方不能同時進行。

SELECT product_id FROM feature_values WHERE variant_id IN ('162', '11819') 

OR

SELECT product_id FROM feature_values WHERE variant_id = '162' OR variant_id = '11819' 
1
SELECT product_id FROM feature_values WHERE variant_id = '162' OR variant_id = '11819' 

SELECT product_id FROM feature_values WHERE variant_id in ('162','11819')