I have a table like this:
ID | Type | woof | meow
1 | dog | 1 | 0
2 | cat | 1 | 1
3 | dog | 0 | 0
4 | cat | 0 | 1
I want to SELECT DISTINCT id, type WHERE if type=dog then woof=1, and if type=cat then meow=1. So my expect output would consist of row 1,2 and 4.
How can I do this? I am assuming with some sort of fancy IF or CASE statement but I couldn’t easily figure it out from mysql’s documentation.
Thanks
You can use AND and OR:
Note also that if your
idfield is unique (and I’m guessing that it is) then the DISTINCT is unnecessary here.