Skip to content

Instantly share code, notes, and snippets.

@Freeaqingme
Created March 12, 2013 12:45
Show Gist options
  • Save Freeaqingme/5142594 to your computer and use it in GitHub Desktop.
Save Freeaqingme/5142594 to your computer and use it in GitHub Desktop.
create temporary table tmpBrands (
`id` int(10) unsigned NOT NULL,
`code` varchar(10) NOT NULL DEFAULT '',
new_id int(10) unsigned NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8;
insert into tmpBrands
SELECT b.id, b.code, (
SELECT b1.id
FROM brands b1
LEFT OUTER JOIN brands b2 ON (
b1.code = b2.code
AND b1.id > b2.id)
where b2.id is null and UPPER(b1.code) = UPPER(b.code)
)
from brands b;
update accounts a set a.brand_id = (select b.new_id from tmpBrands b where b.id = a.brand_id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment