[英]Multiple where in same table mysql?
我在MYSQL上有一個名為“ option_product”的表
Id id_product id_option id_value
1 1 34 77
2 2 34 74
3 1 2 12
4 2 2 10
5 3 2 18
我想做這樣的事情
select id from option_product where
id_option = 34 and id_value = 77
and
(id_option=2 and id value= 12 or id_option=2 and id value= 5)
我怎樣才能做到這一點?
查詢應返回具有所有條件的id_product,例如if(id_option = 34和id_value = 77)和(id_option = 2和id_value = 12或id_option = 2和id_value = 10)它將返回id_product = 1
Select id
From option_product
Where (id_option = 34 And id_value = 77) Or (id_option = 2 And id_value In (12, 5))
這將使您包含(option_id,id_value)->(34,77),(2,12)和(2,5)的行
我認為您真正的意思是:
select id from option_product where (id_option = 34 and id_value = 77)
OR (id_option=2 and id value= 12)
OR (id_option=2 and id value= 5)
嘗試這個 :
select id from option_product where
(id_option = 34 and id_value = 77)
or
(id_option=2 and (id_value= 12 or id_value= 5) )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.