Finding duplicate values in a SQL table

后端 未结 30 4083
南旧
南旧 2020-11-21 13:18

It\'s easy to find duplicates with one field:

SELECT name, COUNT(email) 
FROM users
GROUP BY email
HAVING COUNT(email) > 1

So if we have

30条回答
  •  臣服心动
    2020-11-21 13:41

    If you wish to see if there is any duplicate rows in your table, I used below Query:

    create table my_table(id int, name varchar(100), email varchar(100));
    
    insert into my_table values (1, 'shekh', 'shekh@rms.com');
    insert into my_table values (1, 'shekh', 'shekh@rms.com');
    insert into my_table values (2, 'Aman', 'aman@rms.com');
    insert into my_table values (3, 'Tom', 'tom@rms.com');
    insert into my_table values (4, 'Raj', 'raj@rms.com');
    
    
    Select COUNT(1) As Total_Rows from my_table 
    Select Count(1) As Distinct_Rows from ( Select Distinct * from my_table) abc 
    

提交回复
热议问题