0

I try to count all double entries in a database table. I use a mariadb with myphpadmin.

If I use:

SELECT 
    cd1.*
FROM
    (SELECT 
        kunde,
            COUNT(DISTINCT kunde) AS counterkunde
    FROM
        bot_temp
    GROUP BY kunde) AS cd2,
    bot_temp cd1
WHERE
    cd2.counterkunde > 1
        AND cd1.kunde = cd2.kunde
ORDER BY cd1.kunde

I do not get any double entry. But I made some double entries to debug. Table looks like

id | kunde | created_at

Any idea what is wrong in my SQL query?

IFThenElse
  • 131
  • 1
  • 10

1 Answers1

0

It's DISTINCT that eliminates all the duplicates on your query. Just remove it and try again

...
(SELECT kunde,
        COUNT(kunde) AS counterkunde
...

db_fiddle

ekochergin
  • 4,109
  • 2
  • 12
  • 19