Complex mysql insertion

I have problems recording one request. For example, I have a table with field names and a name that looks like

ID | Name
---+------
1  | John 
2  | Ben
3  | Bob

And the second table with the name of the fields and some field. I need to populate this table using the data from the first, so that it looks like

name | somefield
-----+-----------
John | blah=1
Ben  | blah=2
Bob  | blah=3

So, the value of name is the name from the first table, and the value of some field is some phrase like blah = + id from the first table. Is this possible with mysql? I tried to do this using the loop class and wp wpdb, but wpdb kept throwing some malloc error (I think) after ~ every 30 lines

+5
source share
3 answers
insert into second_table select Name, concat('blah=', ID) from first_table;

. first_table . MySQL , . , , , .

+1
INSERT INTO table2 SELECT Name,CONCAT('blah=',ID) FROM table1;
+2

It should not be too complicated. You don't need loops, just use the statement INSERT SELECT:

INSERT INTO table2(name, somefield)
SELECT name, CONCAT('blah=', id')
FROM table1
+1
source

All Articles