Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL]Jak usunąć ten same id's i zostawić tylko jeden?
Forum PHP.pl > Forum > Przedszkole
Saki
W kolumnie ID mam kilka tych samych numerów, jak usunąć je i zostawić tylko jeden id?
Pyton_000
masz kilka takich samych rekordów? Chcesz zostawić obojętnie który?
Saki
<l__q> How do delete in column all duplicate ID's and leave just one?
<threnody> !t l__q about dupes
<ubiquity_bot> l__q: find them with SELECT COUNT(*) as qty,dupefield[,otherfields] FROM table GROUP BY dupefield[,otherfields] HAVING qty > 1
<threnody> !t l__q about delete dupes
<ubiquity_bot> l__q: If you have a unique ID and the name may contain duplicates then DELETE t1 FROM table1 AS t1 JOIN table1 AS t2 ON t1.id>t2.id AND t1.name=t2.name; If you have other fields that need to be taken into consideration extend the join as needed. If it fails on a myisam table see http://bugs.mysql.com/bug.php?id=28837
<threnody> l__q: if you don't care which rows are deleted you can just do ALTER IGNORE TABLE foo ADD UNIQUE(`col`); <-- that will add a unique index on the column in question and drop duplicate rows
<threnody> l__q: backup first, of course
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.