I have a SQL table like this
id | firstname | lastname
--------------------------
1 | alex | smith
2 | bush | hall
3 | cris | cruise
4 | diana | krall
And i need two column are "firstname" and "lastname" will merge into a column is "name", and a comma will separated them, like this:
id | name
----------------
1 | alex, smith
2 | bush, hall
3 | cris, cruise
4 | diana, krall
Thanks in advance.
You can use CONCAT() function
SELECT id,
CONCAT(firstname,',',lastname) AS `name`
FROM table
Also with CONCAT_WS
SELECT id,
CONCAT_WS(',',firstname,lastname) AS `name`
FROM table
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.