开发者

display one of two fields in every row

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜