Number of duplicate mysql

I have a table like this

mysql> desc user_changes; +----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | id | varchar(16) | NO | PRI | | | | email | varchar(255) | YES | MUL | NULL | | | products | longtext | YES | | NULL | | +----------+--------------+------+-----+---------+-------+ 3 rows in set (0.00 sec) 

And I need to create a query that will read all duplicate emails like this

  | 20061129180346 | test@test.com | 1^31^9 | 20061129330638 | test@test.com | 1^31^9 
+4
source share
5 answers
 SELECT count(*), email FROM user_changes GROUP BY email HAVING count(*) > 1 

The last sentence ( HAVING ) restricts the choice for counting email, which is> 1, for example. duplicates.

+9
source
 select email, count(email) as email_count from user_changes group by email having count(email) > 1 order by email asc 
+1
source

I don’t understand your second block, but to get the score of each letter,

 SELECT email, COUNT(*) AS count FROM user_changes GROUP BY email WHERE count > 1; 
+1
source
 select email, count(*) from user_changes group by email having count(*) > 1 
+1
source

This will count how many of each email address are in the table, not counting the case of the email address. For example, " test@test.com " and " TEST@TEST.COM " will be treated as the same email address. It also just shows duplicates, any email address that just occurs once will not be returned. If you want to return them, simply omit the "HAVING" clause.

 SELECT LOWER(email) EmailAddress, COUNT(*) EmailCount FROM user_changes GROUP BY LOWER(email) HAVING COUNT(*) > 1; 
+1
source

Source: https://habr.com/ru/post/1341327/