Hi,
I need some assistance with a mysql query. I have a table with five fields, lets say it looks like this (fields separated by a dash):
id - item1 - item2 - item1_deleted - item2_deleted
Now, what I want to do is select rows which contain the item number '25', now depending on whether item number '25' is located in the field 'item1' or 'item2' I want to also check that the corresponding deleted field contains "0" (i.e. it is not deleted)
now what I came up with is the following:
select i.*
from items i
where (i.item1 = '25' or i.item2 = '25')
and if(i.item1 = '25' and i.item1_deleted = 1, 0, 1)
and if(i.item2 = '25' and i.item2_deleted = 1, 0, 1)
....
As you can see, the problem arises when the condition is not met, it the goes on to do as if i queried "where 1" so it pulls all the results. However i only want that condition to resolve foe that particular section. It's kind of hard to describe but I think I explained what i am trying to do in the first paragraph.
Any help is greatly appreciated.
Thanks!