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

0 votes

Using MySQL, I want to combine two columns in a table with an already-existing column name. As an illustration, I have several columns, including FIRSTNAME and LASTNAME. These two columns should be combined with the word FIRSTNAME alone.

So I tried this:

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

The two fields with the name FIRSTNAME are still visible. Normal values are present in one field while concatenated values are present in another. With those concatenated values, I just want one column. I have a table with more than 40 columns, however, I can only select single columns.

Can the original column be deleted using MySQL by itself?

Sep 6, 2022 in Database by Kithuzzz
• 38,000 points
734 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

There is no way to exclude a specific column from the * directive, as aziz-shaikh has noted, however, you might be able to apply the following workaround:

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

You should be able to address your customized FIRSTNAME column safely after doing this because the second instance of the FIRSTNAME column will take on the alias FIRSTNAME 1. Because * in any place other than the start will fail without aliasing, you must alias the table.

answered Sep 8, 2022 by narikkadan
• 63,600 points

edited 5 days ago

Related Questions In Database

0 votes
1 answer

How to display the queries executed by a particular user in MySQL?

From the version 5.1.7 onward, MySQL allows ...READ MORE

answered Mar 7, 2019 in Database by Mishti
• 480 points
4,633 views
0 votes
1 answer

How to generate the statement CREATE TABLE for an existing table in postgreSQL?

Generate table creation statement for an existing ...READ MORE

answered Feb 9, 2022 in Database by Neha
• 9,020 points
6,883 views
0 votes
1 answer
0 votes
0 answers

How to get address, Column Name and Row Name of all marked rows in Excel table as rows in new worksheet

 need the row/column combinations marked with an ...READ MORE

Feb 24, 2022 in Database by Edureka
• 13,690 points
2,189 views
0 votes
1 answer
0 votes
1 answer

How to transform multiple tables in one excel sheet to one table with Power BI?

If my prediction is correct- You have a ...READ MORE

answered Apr 4, 2022 in Database by Edureka
• 13,690 points
3,042 views
0 votes
1 answer

Want a command to be executed in Salt only if a directory is empty

You should consider using this inside your ...READ MORE

answered Jun 12, 2018 in DevOps Tools by Damon Salvatore
• 5,980 points
1,945 views
0 votes
1 answer

Creating A New MySQL User In Amazon RDS Environment

AWS RDS security groups documentation (a common ...READ MORE

answered Jul 18, 2018 in AWS by Priyaj
• 58,020 points
2,150 views
0 votes
1 answer

Using conditional to execute a command in salt

You can use unless inside your state ...READ MORE

answered Jul 23, 2018 in Other DevOps Questions by DareDev
• 6,890 points
2,175 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP