Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complex mysql insert

Tags:

mysql

I have problems writing one query. For example, I have table with fields id and name which looks like

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

And second table with fields name and somefield. I need to populate this table using data from first one so it looks like

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

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

like image 318
Igor Yavych Avatar asked Oct 08 '22 01:10

Igor Yavych


1 Answers

INSERT INTO table2 SELECT Name,CONCAT('blah=',ID) FROM table1;
like image 150
CyberDem0n Avatar answered Oct 13 '22 05:10

CyberDem0n