Hey guys am having a nightmare trying to figure out how to copy all the rows from a select query and insert to another table.
My query returns this result after running this query SELECT wp_rg_lead.id, wp_rg_lead.created_by, wp_usermeta.meta_key, wp_usermeta.meta_value, wp_usermeta.user_id from wp_rg_lead
inner join wp_usermeta
on wp_rg_lead.id = wp_usermeta.user_id where wp_usermeta.meta_key = 'parents_id' and wp_rg_lead.id = 12;
INSERT INTO yourtable (yourcolumns) select * from yourothertable
If you want to select into an existing table use the following format:
INSERT INTO destination_table
(column1,column2, etc...)
SELECT wp_rg_lead.id,
wp_rg_lead.created_by,
wp_usermeta.meta_key,
wp_usermeta.meta_value,
wp_usermeta.user_id
FROM wp_rg_lead
inner join wp_usermeta on wp_rg_lead.id = wp_usermeta.user_id
WHERE wp_usermeta.meta_key = 'parents_id' and wp_rg_lead.id = 12;
Alternatively if you want to select them into a brand new table you can use this formate to create the table then insert the values:
SELECT wp_rg_lead.id,
wp_rg_lead.created_by,
wp_usermeta.meta_key,
wp_usermeta.meta_value,
wp_usermeta.user_id
INTO destination_table
FROM wp_rg_lead
inner join wp_usermeta on wp_rg_lead.id = wp_usermeta.user_id
WHERE wp_usermeta.meta_key = 'parents_id' and wp_rg_lead.id = 12;
In either query you need to change the destination_table to the new table name. In the first query you need to supply column names as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.