开发者

Select different field in mysql if a field is set to null?

开发者 https://www.devze.com 2022-12-08 15:36 出处:网络
I want to select displayname as username if username =null and if username is NOT NULL then select userna开发者_如何学Pythonme as username

I want to select displayname as username if username =null and if username is NOT NULL then select userna开发者_如何学Pythonme as username eg.

id username displayname
1   xyz       NULL
2   NULL      abc

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


coalesce(username, dispalyname) should help you.

E.g.:

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

精彩评论

暂无评论...
验证码 换一张
取 消