Skip to content
Advertisement

MYSQL – How to check if a column has value or is it null and another column has value like 10

Lets say i have a table with 3 columns id, user and status. I need to find rows which have status as 1 or null and user = ‘someName’

I am lookin for a condition like this: if (user == ‘name’ && status == 1 || status == null)

How do i do this in mysql

Advertisement

Answer

Just:

This can be simplified as the shorter (but possibly less efficient)


Note that this does not exactly the same thing as your pseudo-code:

Is equivalent to:

Which would translate as:

My understanding of your question, however, is that you meant the first above conditions.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement