I'm working on a project, but I would like to know how I get the first name, middle name and last name as the username with a dot in between their full names and a number at the end for a unique username? In MySQL. Just like Facebook's system. I also want so if the middle name is
NULL
, then it doesn't like a space in the middle.
I have tried a lot of different things, but nothing worked yet.
SELECT COALESCE(CONCAT(first_name, '.', COALESCE(CONCAT(middle_name, '.', last_name),
first_name,middle_name,last_name)), middle_name,'.', COALESCE(CONCAT(first_name, '.',
last_name),first_name,last_name)) AS username FROM users
That is how close I have come, but it has a problem if they don't have a middle name, it will display two dots instead of one. But I still need something to get the first name, middle name and last name as the username with a dot in between their full names and a number at the end for a unique username.