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
精彩评论