SQL getting rows that match my condition -
i have simple sql table has following :
+---------------------+ | id | mode | value | +---------------------+ | 1 | exclude | 10 | | 2 | include | 10 | | 3 | exclude | 10 | | 3 | exclude | 20 | +---------------------+
so imagine these products. product 1, has values 10. product 2 has value 10 only. product 3 has values 10 , 20.
i need sql given value, should return products value valid.
e.g. value of 10 should return product 2. value of 30 should return product 1 , 3.
tried :
select * products ( mode = 'include' , value in( 10) ) or ( mode = 'exclude' , value not in ( 10 ) )
for value 10 example, return 4th row, expected based on sql. how can fix it? want group somehow exclude ones based on id , check values inside ?
select distinct p.id products p exists ( select 1 products id = p.id , value = 10 , mode = 'include' ) or not exists ( select 1 products id = p.id , value = 10 , mode = 'exclude')
Comments
Post a Comment