开发者

display one of two fields in every row

开发者 https://www.devze.com 2023-03-31 07:13 出处:网络
I have table like: +------+-----+ name | 开发者_StackOverflow中文版nick| +------+-----+ yosi | Y|

I have table like:

+------+-----+
| name | 开发者_StackOverflow中文版nick|
+------+-----+
| yosi | Y   |
| adam | NULL|
+------+-----+

I need output of one column, of nick if nick is not null, or of name if nick is null.

like this:

+------+
|result|
+------+
| Y    |
| adam |
+------+

Is there a query for that ?


SELECT IFNULL(nick, name) as result FROM table

This will work in MySQL. See documentation here.


SELECT ISNULL(nick, name) as result FROM table 

for Access and SQL server


In Access, I use the nz() function for that, eg:

SELECT nz(nick, name) as result FROM table
0

精彩评论

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