filips filips - 4 months ago 5
MySQL Question

SQL query: SELECT * FROM table WHERE private = 0 "unless" user = 'username'

I would like to have query that would select from the database all the information which is private = 0 unless the user = 'username'

Like this:

SELECT * FROM table WHERE private = 0 "unless" user = 'username'

Answer

Answer to original question:

SELECT * FROM table 
WHERE private = 0 
and user <> 'username'

EDIT: OP added the following comment:

What if I want to choose where private = 0 unless private = 1 and user = 'username'

Then it sounds like you simply want this (but it's not 100% clear):

SELECT * FROM table 
WHERE private = 0 
OR (private = 1 and user = 'username')
Comments