Milan Novota
Milan Novota

Reputation: 15598

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!

Upvotes: 0

Views: 715

Answers (1)

Ivan
Ivan

Reputation: 2262

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

Upvotes: 6

Related Questions