Created
March 12, 2013 12:45
-
-
Save Freeaqingme/5142594 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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