// создание таблицы
$sql =" CREATE TABLE `translation`

CMSDb::query($sql);

$sql = "INSERT INTO `translation2` SELECT * FROM `translation`";
CMSDb::query($sql);

echo $sql.'
' ;

$sql = "DELETE FROM translation2 WHERE pt='' AND en='' AND ru='' ";
CMSDb::query($sql);

echo $sql.'
';

$sql = "ALTER TABLE `translation2` CHANGE `keystring` `keystring` VARCHAR( 333 )";
CMSDb::query($sql);

echo $sql.'
';
$sql = "ALTER IGNORE TABLE `translation2` ADD UNIQUE INDEX (keystring) ";
CMSDb::query($sql);

echo $sql.'
';

$sql = "SELECT keystring from `translation2` ";
$arr = CMSDb::fetchAll($sql,'keystring');

// var_dump($arr);
// всего 2000 записей
foreach ($arr as $keystr => $val){
// if (!strpos($keystr ,"'")){
$keystrE = CMSDb::e($keystr);
$sql = "update translation2 t2 set t2.en = ( select t1.en from translation t1 where t1.keystring = '".$keystrE."' and t1.en !='' limit 0,1) where t2.en ='' and t2.keystring = '".$keystrE."' ";
CMSDb::query($sql);
$sql = "update translation2 t2 set t2.ru = ( select t1.ru from translation t1 where t1.keystring = '".$keystrE."' and t1.ru !='' limit 0,1) where t2.ru ='' and t2.keystring = '".$keystrE."' ";
CMSDb::query($sql);
$sql = "update translation2 t2 set t2.pt = ( select t1.pt from translation t1 where t1.keystring = '".$keystrE."' and t1.pt !='' limit 0,1) where t2.pt ='' and t2.keystring = '".$keystrE."' ";
CMSDb::query($sql);
// }
}
echo $sql.'

';
$sql = "INSERT IGNORE INTO `translation2` SELECT * FROM `translation`";
CMSDb::query($sql);
// Переименовываем старую таблицу на новую
$sql = "rename table translate to translate3 ";
// CMSDb::query($sql);
$sql = "rename table translate2 to translate ";
// CMSDb::query($sql);

  One Response to “Удаление дублей в таблице sql”

  1. Да, действительно хорошо чистится. Крайне благодарен.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

 
© 2012 Программирование в удовольствие Яндекс.Метрика Suffusion theme by Sayontan Sinha