Оставить игроков (при условии, что они зарегистрировались первыми)
SELECT min(player_id) as player_id
FROM players
GROUP BY lower(uname)
Используйте его, чтобы отобразить удаленных пользователей и их соответствующих хранителей.
SELECT
players.player_id delete_id,
players.uname delete_uname,
keepers.uname keeper_uname,
keepers.player_id keeper_id
FROM players JOIN
(
SELECT p.player_id, p.uname
FROM players p JOIN
(
SELECT min(player_id) player_id
FROM players
GROUP BY lower(uname)
) as keeper_ids
ON (p.player_id = keeper_ids.player_id)
) as keepers
ON (lower(players.uname) = lower(keepers.uname) AND players.player_id <> keepers.player_id)
ORDER BY keepers.player_id, players.player_id
Выход:
delete_id | delete_uname | keeper_uname | keeper_id
---------------------------------------------------
544 | bob | BOB | 34