Reputation: 134
So say I have something like this
SELECT CONCAT(fname, " " IFNULL(mname, ""), lname) FROM name
how would I add a space to that statement if mname is not null? Nothing i've tried has worked and I'm kind of lost. Obviously I can do something like
SELECT CONCAT(fname, " " IFNULL(mname, ""), " " lname) FROM name
but then that gives me two spaces instead of 1.
Upvotes: 1
Views: 34
Reputation: 15758
Use another CONCAT
in the middle name:
SELECT CONCAT(fname,
IF(mname is null, "", CONCAT(" ", mname)),
" " lname)
FROM name
Upvotes: 1