sql - MySQL special INSERT/SELECT statement required for updating while copying rows in a table -



sql - MySQL special INSERT/SELECT statement required for updating while copying rows in a table -

table a: column type, column type_id, column_owner, column_data1, column_data2, , on ----------- -------------- ------------ ------------ ------------ 'type a' 43 'owner sally' 'dfawerfd' 'yiyiyitit' 'type b' 51 'owner sally' 'hufvgdfd' 'weysdgjed' 'type c' 77 'owner sally' '3fdfsetr' '4tgfgert4' table b: column type, column type_id, column_owner ----------- -------------- ------------ 'type a' 43 'owner sally' 'type b' 51 'owner sally' 'type c' 77 'owner sally' 'type a' 100 'owner harry' 'type b' 111 'owner harry' 'type c' 150 'owner harry'

help needed develop 1 magic sql statement insert new rows in table copies of rows in table a.column_owner = 'owner sally'; , each new record inserted, column values should copied a.column_owner should set 'owner harry' , a.type_id should set b.type_id a.type == b.type , b.column_owner == 'owner harry'.

so, new table like:

table a: column type, column type_id, column_owner, column_data1, column_data2, , on ----------- -------------- ------------ ------------ ------------ 'type a' 43 'owner sally' 'dfawerfd' 'yiyiyitit' 'type b' 51 'owner sally' 'hufvgdfd' 'weysdgjed' 'type c' 77 'owner sally' '3fdfsetr' '4tgfgert4' 'type a' 100 'owner harry' 'dfawerfd' 'yiyiyitit' 'type b' 111 'owner harry' 'hufvgdfd' 'weysdgjed' 'type c' 150 'owner harry' '3fdfsetr' '4tgfgert4'

i have 13,000+ records in table copy/update, 1 sql command if possible job appreciated.

i forwards community's help here, give thanks you!

there no way upfront know if satisfies 13.000 records illustration you've given, next statement trick.

the gist of query to

join both tables on column_type selectthe appropriate fields each table insert records in tablea

sql statement

insert tablea select a.column_type , b.column_type_id , b.column_owner , a.column_data1 , a.column_data2 tablea inner bring together tableb b on b.column_type = a.column_type b.column_owner = 'owner harry'

mysql sql

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -