Keoma Borges
Keoma Borges

Reputation: 694

Select a field. If it's null, select another

In my user table, there's email and number fields. I have to select the email. But if it is null, select the number. Can I do this in one query?

Thanks.

Upvotes: 2

Views: 121

Answers (1)

John Woo
John Woo

Reputation: 263703

you can use COALESCE

SELECT COALESCE(email, number)
FROM   tableName

From Docs,

Returns the first non-NULL value in the list, or NULL if there are no non-NULL values.

Upvotes: 4

Related Questions