I'm trying to write a query which excludes certain records conditionally depending on the value of another field in the same table. The logic would be as follows...
If ChairType is 1
Exclude all records where the ChairAge = 2
WHERE (`ChairAge` != '2' WHEN `ChairType` = '1') AND blah=blah AND blah=blah etc. etc...
This is just a portion of a very long query. I took a stab at using the WHEN clause with parantheses but it doesn't work. Any ideas? Couldn't find anything in the manual.
I checked the results and the query won't work because it's excluding results where the ChairType isn't equal to 1. That is why I need to use something like a WHEN clause. Is there a way to make this work with a query?
select blah CASE `ChairType` WHEN '1' THEN `ChairAge` < '2' ELSE END CASE AND blah
select blah (CASE `ChairType` WHEN '1' THEN `ChairAge` < '2' ELSE END CASE) AND blah
select blah (CASE `ChairType` WHEN '1' THEN `ChairAge` < '2' ELSE CASE) AND blah
select blah (CASE `ChairType` WHEN '1' THEN `ChairAge` < '2' ELSE CASE;) AND blah
select blah (`ChairAge` < '2' IF(`ChairType` = '1')) AND blah
select blah (`ChairAge` < '2' IF `ChairType` = '1') AND blah
select blah (`ChairAge` < '2' WHEN `ChairType` = '1') AND blah
select blah (`ChairAge` < '2' WHERE `ChairType` = '1') AND blah