简体   繁体   中英

Concat in MySQL with condition

I have three columns in my table - company_name, first_name, last_name . In the result of a SELECT , I'd like to have only one column: name , which should contain content of company_name if it's not NULL or concatenation of first_name +' '+ last_name , if the company_name is not set.

Any advice? Thanks!

SELECT IFNULL(company_name,CONCAT(first_name,' ',last_name)) as NAME

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM