how to concat two columns into one with the existing column name in mysql?

后端 未结 6 1554
旧时难觅i
旧时难觅i 2020-12-07 13:22

I want to concatenate two columns in a table with a existing column name using mysql.

An example: I am having a column FIRSTNAME and LASTNAME

6条回答
  •  -上瘾入骨i
    2020-12-07 13:28

    Remove the * from your query and use individual column names, like this:

    SELECT SOME_OTHER_COLUMN, CONCAT(FIRSTNAME, ',', LASTNAME) AS FIRSTNAME FROM `customer`;
    

    Using * means, in your results you want all the columns of the table. In your case * will also include FIRSTNAME. You are then concatenating some columns and using alias of FIRSTNAME. This creates 2 columns with same name.

提交回复
热议问题