views:

215

answers:

1

I want to select displayname as username if username =null and if username is NOT NULL then select username as username eg.

id username displayname
1   xyz       NULL
2   NULL      abc

How can I do that in one single select statement...Thanks

+4  A: 

coalesce(username, dispalyname) should help you.

E.g.:

select coalesce(username, dispalyname) from users
where ...
elder_george