fr33jumper
fr33jumper

Reputation: 103

mysql multiple conditions with not equal

I want something like this:

SELECT * FROM chat 
WHERE (user1= :user OR user2= :user) 
AND (deleted1 != :user OR deleted2 != :user) 
ORDER BY year, month, day, time DESC 
LIMIT 20

I have this code:

SELECT * FROM chat 
WHERE user1= :user OR user2= :user 
AND deleted1 <> :user OR deleted2<> :user 
ORDER BY year, month, day, time DESC 
LIMIT 20

I want to first check if is :user in user1 or user2 and after that to check if :user not in deleted1 or deleted2. In many cases deleted1 and deleted2 are both empty. But this code what I have it not working like I want.

enter image description here

This is my table and i want to display all rows where not user1 or user2 in deleted1 or deleted2

Upvotes: 0

Views: 1245

Answers (1)

Ashutosh
Ashutosh

Reputation: 21

You can try with the following query

SELECT *   FROM chat
WHERE      (user1= :user OR user2= :user)
AND        ( deleted1 <> :user )
AND        ( deleted2<> :user)
ORDER BY year, month, day, time DESC
LIMIT 20

Upvotes: 2

Related Questions