Ben Clayton Ben Clayton - 7 months ago 17
SQL Question

SQL Query If Statement?

I have two fields in a legacy database. I want to query one of them, but its often

, In this case is there like an
like Where if field_a !== null { field_a='Value' } else { field_b='Value' }

My Question is, is there a way to do this in sql itself or would i have to do two queries, one to check if null, then an if statement in my logic?


I think you can capture the logic like this:

where field_a = 'Value' or (field_a is NULL as field_b = 'Value')

or more simply as:

where field_a = 'Value' or field_b = 'Value'