1

I have a table as below:

enter image description here

Here, I wanna run a query which looks like this:

SELECT model_id 
FROM model_attributes 
WHERE ((attributes_id=2 and attributes_value='32mb')) AND ((attributes_id=4 AND attributes_value='5.00 inch') OR (attributes_id=4 and attributes_value='6.00 inch')) AND ((attributes_id=5 and attributes_value='here') OR (attributes_id=5 and attributes_value='asfdsdf'))

which returns model_ids 8, 9. But it seems like I can't put multiple conditions in the same fields.

I also tried solutions in this post still nothing ! How can I get this result ? The way I used the AND clause is incorrect but resembles what logic I wanna implement in the query.

Rabin Lama Dong
  • 2,422
  • 1
  • 27
  • 33

2 Answers2

2

You are asking for rows where attributes_id is 2 and 4 and 5, that will never be true.

Try this:

WHERE (attributes_id=2 AND attributes_value='32mb') OR 
(attributes_id=4 AND attributes_value in ('5.00 inch', '6.00 inch') OR 
(attributes_id=5 AND attributes_valuein ('here', 'asfdsdf')
papkass
  • 1,261
  • 2
  • 14
  • 20
0
SELECT model_id 
FROM model_attributes 
WHERE ((attributes_id=2 and attributes_value='32mb')) or ((attributes_id=4 AND attributes_value='5.00 inch') OR (attributes_id=4 and attributes_value='6.00 inch')) or ((attributes_id=5 and attributes_value='here') OR (attributes_id=5 and attributes_value='asfdsdf'))

make and to orlike above i think and was logically wrong

SF..MJ
  • 862
  • 8
  • 19