IF DUPLICATE ENTRIES?
kallmund
- php
Hi,
wie kann ich mit einer mysql-abfrage herausfinden ob ich doppelte einträge in meiner tabelle habe. ein primary key ist definiert...
id | a | b | block
1 | 1 | 1 | 1
2 | 2 | 1 | 1
3 | 1 | 2 | 1
4 | 2 | 2 | 1
5 | 1 | 3 | 1
6 | 2 | 3 | 1
7 | 1 | 4 | 2
8 | 2 | 4 | 2
9 | 1 | 5 | 2
10 | 2 | 5 | 2
11 | 1 | 3 | 2
12 | 2 | 3 | 2
ich möchte dopellte einträge ohne berücksichtgung des primary keys und ohne berücksichtigung der "block"-id doppelte einträge finden.
id | a | b | block
1 | 1 | 1 | 1
2 | 2 | 1 | 1
3 | 1 | 2 | 1
4 | 2 | 2 | 1 <
5 | 1 | 3 | 1 <
6 | 2 | 3 | 1
7 | 1 | 4 | 2
8 | 2 | 4 | 2
9 | 1 | 5 | 2
10 | 2 | 5 | 2
11 | 1 | 3 | 2 <
12 | 2 | 3 | 2 <
wie bekomme ich das hin?
kalli
sorry.....
ich hab die < falsch gesetzt!... also nochmal
id | a | b | block
1 | 1 | 1 | 1
2 | 2 | 1 | 1
3 | 1 | 2 | 1
4 | 2 | 2 | 1
5 | 1 | 3 | 1 <
6 | 2 | 3 | 1 <
7 | 1 | 4 | 2
8 | 2 | 4 | 2
9 | 1 | 5 | 2
10 | 2 | 5 | 2
11 | 1 | 3 | 2 <
12 | 2 | 3 | 2 <
kalli
Hi,
id | a | b | block
1 | 1 | 1 | 1
2 | 2 | 1 | 1
3 | 1 | 2 | 1
4 | 2 | 2 | 1
5 | 1 | 3 | 1 <
6 | 2 | 3 | 1 <
7 | 1 | 4 | 2
8 | 2 | 4 | 2
9 | 1 | 5 | 2
10 | 2 | 5 | 2
11 | 1 | 3 | 2 <
12 | 2 | 3 | 2 <
mit
SELECT id, count(*) FROM <TABELLENNAME> GROUP by a,b;
bekommst du fuer alle Doppelten eintraege einen Wert > 1 fuer count(*)
Ob du das noch irgendwie mit einer Where-Klausel verbinden kannst weiss ich jedoch nicht.
mfG,
steckl
Hey,
SELECT id, count(*) FROM <TABELLENNAME> GROUP by a,b;
bekommst du fuer alle Doppelten eintraege einen Wert > 1 fuer count(*)
das müsste genau das sein was ich suche, danke.
werd ich gleich mal probieren...
kalli
Hi,
ich möchte dopellte einträge ohne berücksichtgung des primary keys und ohne berücksichtigung der "block"-id doppelte einträge finden.
id | a | b | block
1 | 1 | 1 | 1
2 | 2 | 1 | 1
3 | 1 | 2 | 1
4 | 2 | 2 | 1 <
Mit welchem Eintrag ist dieser eintrag doppelt?
5 | 1 | 3 | 1 <
6 | 2 | 3 | 1
Warum wird dieser Eintrag nicht gefunden?
a=2 und b=3 kommt ja weiter unten auch nochmal.
7 | 1 | 4 | 2
8 | 2 | 4 | 2
9 | 1 | 5 | 2
10 | 2 | 5 | 2
11 | 1 | 3 | 2 <
12 | 2 | 3 | 2 <
Ich sehe da keine Logik dahinter, welche Eintraege gefunden werden und welche nicht.
Vielleicht solltest du das nochmal etwas genauer erklaeren.
mfG,
steckl
Hello,
wie kann ich mit einer mysql-abfrage herausfinden ob ich doppelte einträge in meiner tabelle habe. ein primary key ist definiert...
Mit einem Self-Join
Und dann schrei bitte nicht so
Harzliche Grüße vom Berg
http://www.annerschbarrich.de
Tom