'Copy content from one MYSQL table to another

Suppose I have two tables, tableA has multiple rows and contains data and tableB has only 2 rows and is empty.

tableA

id |  name   |  lastname  |  age
--------------------------------
1  |  John   |  Doe       |  40 
2  |  Paul   |  Miller    |  26 
3  |  Mary   |  Brown     |  32 


tableB

id |  fullname  
--------------
   Empty

I'd like to know if it's possible to have a query string to copy the ids and concatenate the name and last name and copy into tableB.

Expected result:

tableB

id |  fullname  
--------------
1  |  John Doe
2  |  Paul Miller
3  |  Mary Brown

Thanks in advance.



Solution 1:[1]

You don't use VALUES when you're inserting from a SELECT query.

INSERT INTO TableB (id, fullname)
SELECT id, CONCAT(name, ' ', lastname)
FROM TableA

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Barmar