rumbledom
Goto Top

Doppelte Datenbankeinträge herausfiltern

MySQL-Datenbanktabelle enthält doppelte (und mehrfache) Datenbankeinträge. Diese sollen mit einem SQL-Statement herausgefiltert werden.

Umgebung:

MySQL-Tabellenname: ARTIKEL
Felder: ID, LIEFERANT, BESTELLNUMMER

ID ist immer fortlaufend, LIEFERANT ist ein INT (beispielsweise 1228), BESTELLNUMMER ist VARCHAR (beispielsweise ABC123)


Lösungsansatz:

SELECT *
FROM ARTIKEL
WHERE COUNT(LIEFERANT) > 1
AND COUNT(BESTELLNUMMER) > 1
GROUP BY BESTELLNUMMER


Leider bin ich damit irgendwie auf dem Holzweg und finde bei Google sowie der MySQL-Doku nicht wirklich eine Lösung oder einen passenden Ansatz hierzu.

Kann mir jemand weiterhelfen?

Gruß, rumble

Content-Key: 187795

Url: https://administrator.de/contentid/187795

Printed on: April 19, 2024 at 06:04 o'clock

Member: Lu22235
Lu22235 Jul 11, 2012 at 08:09:40 (UTC)
Goto Top
Mit DISTINCT kann man Duplikate rausfiltern.
Hier kleine Funktionsbeschreibung. http://www.mysqlfaqs.net/mysql-faqs/Select-Statement/How-does-DISTINCT- ...
Member: nxclass
nxclass Jul 11, 2012 updated at 10:21:05 (UTC)
Goto Top
fehlt da nur ein Group element ?
SELECT *
FROM ARTIKEL
GROUP BY BESTELLNUMMER,LIEFERANT
... nun hast du es gefiltert.
Ich vermute aber mal, dass Du die doppelten Werte löschen willst !?

btw. wenn solche doppelten Werte nicht gewünscht sind, dann setze ein UNIQUE Schlüsselpaar und arbeite mit REPLACE oder INSERT .. ON DUPLICATE KEY UPDATE
Member: rumbleDom
rumbleDom Jul 11, 2012 at 14:48:50 (UTC)
Goto Top
Ich vermute aber mal, dass Du die doppelten Werte löschen willst !?
Korrekt ... Sorry, da habe ich mich mit dem Wort "filtern" etwas unglücklich ausgedrückt face-sad


btw. wenn solche doppelten Werte nicht gewünscht sind, dann setze ein UNIQUE Schlüsselpaar und arbeite mit REPLACE oder
INSERT .. ON DUPLICATE KEY UPDATE
Das funktioniert leider nicht, weil die Auswertung hierzu erst gemacht werden muss und dafür auch die doppelten Werte benötigt werden face-sad
Member: exchange
exchange Jul 11, 2012 at 21:56:02 (UTC)
Goto Top
Hi,
verstehe gerade nicht was Du genau suchen willst aber grundsätzlich würde das z.B. so aussehen:

SELECT mac, count(id) FROM nutzer GROUP BY mac HAVING count(*) > 1

Das zeigt Dir alle MAC Adressen an, welche mehr als einmal in der Datenbank vorkommen.

Gruß
Member: rumbleDom
rumbleDom Jul 12, 2012 at 03:05:54 (UTC)
Goto Top
Treffer!!! HAVING ist es!
Vielen herzlichen Dank.
Member: pokernet88
pokernet88 Jan 24, 2020 at 09:52:06 (UTC)
Goto Top
I would like to convey my affection for your kindness supporting
visitors who actually need help with this important concern. Your personal commitment to
www.beliebtestewebseite.de/hpdetails.php/Select-Statement/How-does-DISTINCT-work-in-MySQL
passing the message all over has been especially effective and has empowered those like me
Member: dewidomino
dewidomino Jan 30, 2020 at 11:05:11 (UTC)
Goto Top
Thanks a lot for giving everyone an extremely breathtaking chance to read from this blog.
It is always so lovely and jam-packed www.davehakkens.nl/community/hpdetails.php/Select-Statement/How-does-DISTINCT-work-in-MySQL
with a great time for me personally and my office peers to visit the blog
not less than three times in a week to see the fresh issues you have.
Member: indipoker
indipoker Feb 04, 2020 at 11:40:18 (UTC)
Goto Top
laptop or laptop device brand and model does not matter whether repair indipoker.com
visitors who actually need help with this important concern. Your personal commitment to
maintenance, repair, spare parts replacement and software problems in providing
Member: bandarxl
bandarxl Feb 09, 2020 at 12:19:56 (UTC)
Goto Top
There was a re-occurring theme all week long. Managers in every department are hungry for data that
will give them improved insight into their operations, and they’re frustrated with the difficulty 13.251.223.198 of acquiring that data without
Member: total4d
total4d Mar 22, 2020 at 07:48:37 (UTC)
Goto Top
the commentary stack on that people remain on point and not get started on a tirade of some other
news of the day. Anyway, thank you for total4d3.com this exceptional point and whilst I can not really go along with
this in totality http://total4d3.com