jogisarge
26-03-2004, 09:43
Hallo zusammen !
Wie kann ich in einer DB doppelte Datensätze finden .
d.h. Ich möchte prüfen, ob der Inhalt eines bestimmten Feldes mehrmals vorkommt .
gruss jogi
SELECT feld, COUNT(feld) anz FROM tabelle WHERE anz > 1 GROUP BY feld
mrhappiness
26-03-2004, 09:48
WHERE anz > 1 :D
wenn schon posen, dann doch bitte richtig ;)
Original geschrieben von mrhappiness
WHERE anz > 1 :D
wenn schon posen, dann doch bitte richtig ;) hehe, das steht doch bei mir schon drin.... :D
ghostgambler
20-08-2005, 00:00
irgendwie...geht das nicht -.-
SELECT `password`, COUNT(`password`) anz
FROM users
WHERE anz > 1
GROUP BY `password`
gibt mir nur nen #1054 - Unknown column 'anz' in 'where clause'
und wenn ich es so mache:
SELECT `password`, COUNT(`password`) anz
FROM users
WHERE COUNT(`password`) > 1
GROUP BY `password`
#1111 - Invalid use of group function
wenn ich das Where jedoch weg lasse, gibt er mir zumindest die Ergebnisse aus
mach mal aus WHERE COUNT(`password`) > 1 ein HAVING COUNT(`password`) > 1
ghostgambler
20-08-2005, 00:17
Original geschrieben von Abraxax
mach mal aus WHERE COUNT(`password`) > 1 ein HAVING COUNT(`password`) > 1
dann tut's gar nicht mehr
SELECT `password` , COUNT( `password` ) anz
FROM users
HAVING COUNT( `password` ) >1
GROUP BY `password`
#1064 - You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server
version for the right syntax to use near 'GROUP BY `password'
at line 4
das HAVING muss wohl NACH GROUP BY rein.
http://dev.mysql.com/doc/mysql/en/select.html
ghostgambler
20-08-2005, 01:00
Original geschrieben von Abraxax
das HAVING muss wohl NACH GROUP BY rein.
http://dev.mysql.com/doc/mysql/en/select.html
ah~
jetzt muss ich nur noch in der Manual gucken was es macht :D
thanks
heddesheimer
20-08-2005, 08:16
Und hier noch mal richtig:
select feld, count(feld) as anz
from tabelle
group by feld
having anz > 1
das funktioniert garantiert ;)
Gruß Marian