SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 duplicate rows
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

maddyslayer
Yak Posting Veteran

57 Posts

Posted - 05/03/2013 :  10:43:44  Show Profile  Reply with Quote
Hi,

Here's the table, T

id email
1 1@1.com
2 2@3.com
3 1@1.com
4 1@1.c0m
5 2@3.com

How do i get all the duplicate emails(like I should get 3 records for 1@1.com)?

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 05/03/2013 :  10:50:47  Show Profile  Reply with Quote

SELECT id,email
FROM
(
SELECT COUNT(1) OVER (PARTITION BY email) AS Occ,*
FROM Table
)t
WHERE Occ > 1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1052 Posts

Posted - 05/03/2013 :  10:51:01  Show Profile  Reply with Quote
SELECT email,count(1) from T group by Email having count(1)>1

Cheers
MIK
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000