SQL Fiddle here: http://sqlfiddle.com/#!2/a2e41/8
I have a query which does a number of checks: whether column uidto or uidfrom contain a given value. This works fine, but as soon as I want to exclude when columns hidden1 or hidden2 contain a given value the query returns the results anyway. As soon as I take out the first uidto, uidfrom check, it returns nothing, which is expected. Is there any way to do all the checks? Is one being ignored in favor of the other?
Any ideas?
edit:
This still returns despite column hidden1 containing the value to check for:
SELECT m.threadid,
m.uidto,
m.uidfrom,
m.type,
m.hidden1,
m.hidden2
FROM messages m
WHERE m.uidto = 1
OR m.uidfrom = 1
AND m.hidden1 <> 1
AND m.hidden2 <> 1
GROUP BY threadid;
This seems to honor the exclusions, but does not do the check for uidfrom or uidto containing 1
SELECT m.threadid,
m.uidto,
m.uidfrom,
m.type,
m.hidden1,
m.hidden2
FROM messages m
WHERE m.hidden1 <> 1
AND m.hidden2 <> 1
GROUP BY threadid;
EDIT:
There are several threadid's and I pull the messages belonging to each user involved in the thread (there will only ever be two users) by checking if a value matches uidto or uidfrom, then checking if a users id is in hidden1 or hidden2.
the value of the hidden1 and hidden2 columns is the users id who has opted to hide the thread from himself.
If user 1 deletes his thread, we put his user id (1) into the hidden1 column so that he can't see it, but the other user can. if user id 22, who is involved in the thread as well wants to delete the thread, user id 22 would go in to hidden2, now neither of them can see that thread.
Message threads will only ever be seen by the person who sent the messages in it, or the person receiving them. Nobody else will be involved.