2015-01-21 54 views
-4

我有一個存儲與產品關聯的屬性值的表。如何寫入mysql select?

row_id product_id attribute_id value 
1 1 1 a 
2 1 2 b 
3 2 1 d 
4 2 2 e 

我該如何寫一個select來獲取attribute_id = 2的值僅適用於value =「a」for attribute_id = 1的產品?

感謝,

有一個愉快的一天

+0

你有什麼嘗試? – 2015-01-21 08:51:28

回答

0

也許這是你想要的嗎?

select * 
from your_table 
where attribute_id = 2 
    and product_id in (
    select product_id 
    from your_table 
    where attribute_id = 1 and value = 'a' 
) 

用您的樣品數據將返回row_id = 2的行。