webForumDet fria alternativet

Radera dubletter?

Databaser & SQL

2 svar · 204 visningar · startad av patrickpolly

Medlem sedan mars 2001190 inlägg
Frågan#1

Någon som hittat ett kommando för att radera dubletter? Jag har tex följande rader:

email | password
name@host.com | hej
name2@host.com | hej
name@host.com | hej

Nu vill jag radera alla rader som redan finns en gång så resultatet blir:
email | password
name@host.com | hej
name2@host.com | hej

Jag kan förvisso skriva ihop ett perlscript som gör det men om det går att göra direkt i MySQL är ju det enklare :)

//Patrik

------------------
Patrik Lindgren - Alxnet AB
Alxnet.se - gratis webbverktyg

Medlem sedan juni 20008 205 inlägg
#2

Jag tror faktiskt inte att det går att göra direkt i MySQL, eftersom det inte stöder subqueries. Däremot att plocka fram dubletter är ju enkelt...

SELECT * FROM tabell t1, tabell t2 WHERE t1.email = t2.email
/* och alternativt även */
AND t1.något_unikt <> t2.något_unikt;

------------------
These are the cries of the carrots, the cries of the carrots! You see, Reverend Maynard, tomorrow is harvest day and to them it is the holocaust.

Medlem sedan mars 2001190 inlägg
#3

Isch, då måste det perlas i alla fall antar jag :/

//Patrik

------------------
Patrik Lindgren - Alxnet AB
Alxnet.se - gratis webbverktyg

261 ms totalt · 4 externa anrop · v20260731065814-full.1dc6f849
128 ms — deklarationer (db)
0 ms — hämta statistik (cache)
130 ms — hämta tråd, inlägg och bilagor (db)
125 ms — ändringar (db)