I have the following table (id, Tag)
with the following values
(1, 17)
(1, 31)
(2, 17)
(3, 31)
When I query the following
"SELECT id FROM table WHERE 1 AND Tag=17 AND Tag=31"
I expected it to return (id)
(1)
But it doesn't. (returns 0 row)
What's wrong here?
For any particular row the tag can't be both 17 and 31. You need
SELECT id
FROM table
WHERE Tag in (17, 31)
GROUP BY id
HAVING COUNT(DISTINCT Tag) = 2
Machines are logic and do what you asked them to do... your expectations are wrong in this case.
Tag 17 AND tag 31 conditions according to boolean math should be satisfied simultaneous to produce results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With