I want to 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 have 2 tables price_drop_apps_temp
and price_drop_apps
that have the 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
and storefront_id
.
I need to copy from table price_drop_app
all values from column price_2
to table price_drop_apps_temp
column price_1
where application_id
AND storefront_id
match in both tables and so on for some other columns. If price_drop_apps_temp
has no matching application_id
AND storefront_id
the values should remain NULL.
I tried following but its not working and I am also not sure if I should use UPDATE
or INNER JOIN
. My SQL skills are very limited so any help appreciated.
INSERT INTO price_drop_apps_temp (price_1,price_2,price_3) SELECT price_2,price_3,price_4 FROM price_drop_apps WHERE price_drop_apps_temp.application_id = price_drop_apps.application_id AND price_drop_apps_temp.storefront_id = price_drop_apps.storefront_id