I have a table that has two columns, one of which will be NULL
and one will not, what I would like to do is something like:
SELECT (column1 OR column2) AS value
But I need to retrieve the value that is not null. I feel like this is probably an easy question, but any help is appreciated.
SELECT COALESCE(column1, column2) AS value
or
SELECT IFNULL(column1, column2) AS value
or
SELECT CASE WHEN column1 IS NOT NULL THEN column1 ELSE column2 END AS value
or
SELECT IF(column1 IS NOT NULL, column1, column2) AS value
In mysql, you can use the IFNULL function. In SQL Server, you can use ISNULL function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With