mysql - Copy/Update values from table_a to another row of table_b WHERE table_a.id = table_b.id AND table_a.name = table_b.name -


i want copy/update values table_a row of table_b table_a.id = table_b.id , table_a.name = table_b.name

i have 2 tables price_drop_apps_temp , price_drop_apps have same structure

create table if not exists `price_drop_apps_temp` (   `application_id` int(11) not null default '0',   `storefront_id` int(11) not null default '0',   `price_1` decimal(9,3) default null,   `price_2` decimal(9,3) default null,   `price_3` decimal(9,3) default null,   `price_4` decimal(9,3) default null,   `price_5` decimal(9,3) default null,   `price_6` decimal(9,3) default null,   primary key (`application_id`,`storefront_id`) ) engine=innodb default charset=utf8 collate=utf8_unicode_ci") 

the table price_drop_apps_temp contains updated application_id , storefront_id.

i need copy table price_drop_app values column price_2 table price_drop_apps_temp column price_1 application_id , storefront_id match in both tables , on other columns. if price_drop_apps_temp has no matching application_id , storefront_id values should remain null.

i tried following not working , not sure if should use update or inner join. sql skills limited appreciated.

insert price_drop_apps_temp (price_1,price_2,price_3) select price_2,price_3,price_4 price_drop_apps price_drop_apps_temp.application_id = price_drop_apps.application_id , price_drop_apps_temp.storefront_id = price_drop_apps.storefront_id 

i'm not quite sure understand needs. but...

i want copy/update values table_a row of table_b table_a.id = table_b.id , table_a.name = table_b.name

you want update columns price[1-3] of 1 table of other table? try that:

update price_drop_apps_temp dst, price_drop_apps src   set dst.price1 = src.price1, dst.price2 = src.price2, dst.price3 = src.price3   dst.application_id = src.application_id      , dst.storefront_id = src.storefront_id 

the where clause has adjusted depending on specific needs (table_a.id/table_a.name ?!?). that's spirit...


if source table contains rows not present in second table, have add second pass insert them:

insert ignore price_drop_apps_temp select * price_drop_apps; 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -