Duplicate Column values in a SQL Table

How to Get Values of column having duplicate records in some other column.

Scenario

I have a table having multiple columns, the two named are ID and email, Now i what i want to do is that i want the values of ID's for those Columns having same email address or duplicate email address. Suppose we have the following table named "Table1" having two fields ID and Email and having following Data.



IDEmail
1Email1@Email.com
2Email1@Email-2.com
3Email1@Email.com
4Email1HK@Email.com
5Email1@Email.com
6Email1HK@Email.com
7Email1@Email.com
8Email1we@Email.net
9Email1sd@Emailz.com
10Email1@Email.com
11Email1n@Email.com
12Email1@Email.com


Use the following SQL Query to get ID's having Duplicate Email address

Select ID from Table1 where Name IN (SELECT Name FROM Table1 GROUP BY Name HAVING ( COUNT(Name) > 1 ))

Now this Query will return 1,3,5,7,10,12,4 and 6 from the above table having same Data.

Comments

Popular posts from this blog

Use configSource attribute to manage Web.Config sections in ASP.Net 2.0

DevOps - Key Concepts - Roles & Responsibilities - Tools & Technologies

Trouble In the House of Google