类似的东西可以帮助你开始
select g1.gameID as toKeep, g2.gameID toEliminate
from games g1
inner join games g2 on replace(g1.internalName, ' ', '') = replace(g2.internalName, ' ', '')
where g1.gameID < g2.gameID
但如果你有 3 个项目要合并,这将不会那么好......
见http://sqlfiddle.com/#!2/fb294/6
但是在存储过程或 php(或其他语言)中,您应该能够得到您想要的东西。
更好的
有了这个,即使是 3、4 或 5 个相同的结果也会起作用
select g1.gameID as toKeep, g2.gameID toEliminate
from games g1
inner join games g2 on replace(g1.internalName, ' ', '') = replace(g2.internalName, ' ', '')
where g1.gameID < g2.gameID
and g1.gameID not in (SELECT g4.gameID
from games g4
inner join games g3 on replace(g3.internalName, ' ', '') = replace(g4.internalName, ' ', '')
where g3.gameID < g4.gameID)
http://sqlfiddle.com/#!2/8fb21/1
编辑:(未经测试的)存储过程的示例
CREATE PROCEDURE CLEANGAMENAMES()
BEGIN
DECLARE toKeep, toEliminate INT;
DECLARE cur1 CURSOR FOR
SELECT g1.gameID AS toKeep, g2.gameID AS toEliminate
FROM games g1
INNER JOIN games g2 ON REPLACE(g1.internalName, ' ', '') = REPLACE(g2.internalName, ' ', '')
WHERE g1.gameID < g2.gameID
AND g1.gameID NOT IN (SELECT g4.gameID
FROM games g4
INNER JOIN games g3 ON REPLACE(g3.internalName, ' ', '') = REPLACE(g4.internalName, ' ', '')
WHERE g3.gameID < g4.gameID)
OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO toKeep, toEliminate;
UPDATE <anyTable> set gameId = toKeep where gameId = toEliminate;
-- as many tables as you need
DELETE FROM games where gameID = toEliminate;
UPDATE games set internalName = REPLACE(internalName, ' ', '');
END LOOP;
CLOSE cur1;
END;