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

后端 未结 6 1539
旧时难觅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条回答
  •  醉梦人生
    2020-12-07 13:49

    As aziz-shaikh has pointed out, there is no way to suppress an individual column from the * directive, however you might be able to use the following hack:

    SELECT CONCAT(c.FIRSTNAME, ',', c.LASTNAME) AS FIRSTNAME,
           c.*
    FROM   `customer` c;
    

    Doing this will cause the second occurrence of the FIRSTNAME column to adopt the alias FIRSTNAME_1 so you should be able to safely address your customised FIRSTNAME column. You need to alias the table because * in any position other than at the start will fail if not aliased.

    Hope that helps!

提交回复
热议问题