MySQL returning an empty field: CONCAT(nonEmpty1,empty2,nonEmpty3) = NULL

前端 未结 6 1139
攒了一身酷
攒了一身酷 2021-02-19 10:27

I have PHP 5 code accessing a MyISAM table on MySQL 5 server. The query looks like this:

SELECT CONCAT(fName1,\' \',mName2,\' \',lName3) AS userName 
    FROM us         


        
6条回答
  •  耶瑟儿~
    2021-02-19 11:08

    From MYSQL docs

    CONCAT() returns NULL if any argument is NULL.

    you want to use CONCAT_WS()

    CONCAT_WS(separator,str1,str2,...)
    

    But best bet is to just pull it back and use php cause if you need a different format or just one of those fields later you'll have to make another db call

提交回复
热议问题