Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL]Jak usunąć ten same id's i zostawić tylko jeden?
Saki
post 30.05.2015, 20:01:53
Post #1





Grupa: Zarejestrowani
Postów: 240
Pomógł: 2
Dołączył: 5.12.2010
Skąd: Fulda

Ostrzeżenie: (0%)
-----


W kolumnie ID mam kilka tych samych numerów, jak usunąć je i zostawić tylko jeden id?


--------------------
Moje serwisy: services.itunix.eu | spytajsie.com

Server: Debian; Desktop: Mac Mini 10.8.1, ArchLinux XFCE
Go to the top of the page
+Quote Post
Pyton_000
post 30.05.2015, 20:24:31
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


masz kilka takich samych rekordów? Chcesz zostawić obojętnie który?
Go to the top of the page
+Quote Post
Saki
post 30.05.2015, 20:31:19
Post #3





Grupa: Zarejestrowani
Postów: 240
Pomógł: 2
Dołączył: 5.12.2010
Skąd: Fulda

Ostrzeżenie: (0%)
-----


<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


--------------------
Moje serwisy: services.itunix.eu | spytajsie.com

Server: Debian; Desktop: Mac Mini 10.8.1, ArchLinux XFCE
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 13.06.2025 - 10:08