Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
PeteLeHoq
Starting Member
37 Posts |
Posted - 2013-10-17 : 11:15:13
|
I'm using this to find duplicates where a person has the same email but varying firstname and lastnames:select distinct t1.booking_id, t1.first_name, t1.last_name, t1.email_add, t1.booking_status_idfrom [aren1002].[BOOKING]as t1 inner join [aren1002].[BOOKING]as t2 on t1.last_name=t2.last_name and t1.booking_id<>t2.booking_idwhere t1.booking_status_id = 330order by last_name asc Sample data:3927 Greg Smith greg@emailno1.com 3035012 John Smith greg@emailno1.com 3036233 John Smith greg@emailno1.com 3034880 Dulcie Abuud dulcie@theiremail.com 303However it is listing the non duplicate rows, For example: The record with Abuud as the last name, doesn't have any duplicates in the table, so I don't want it listed.The data should be like this:3927 Greg Smith greg@emailno1.com 3035012 John Smith greg@emailno1.com 3036233 John Smith greg@emailno1.com 303Thanks |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-10-17 : 11:25:17
|
quote: Originally posted by PeteLeHoq I'm using this to find duplicates where a person has the same name but varying firstname and lastnames:select distinct t1.booking_id, t1.first_name, t1.last_name, t1.email_add, t1.booking_status_idfrom [aren1002].[BOOKING]as t1 inner join [aren1002].[BOOKING]as t2 on t1.last_name=t2.last_name and t1.booking_id<>t2.booking_idwhere t1.booking_status_id = 330order by last_name asc However it is listing the non duplicate rows, ie the rows where an row which has the same email but no varying email.Thanks
A little confused by your statement about "a person has the same name but varying firstname and lastnames". Can you show an example? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-18 : 03:02:28
|
You're telling two thingsfirsta person has the same name but varying firstname and lastnamesand thenwhere an row which has the same email but no varying email.which is actual scenarioIt would be best to explain with some sample data------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
PeteLeHoq
Starting Member
37 Posts |
Posted - 2013-10-18 : 05:54:00
|
Thanks, I've update the post with sample data.I'm trying to find records where the last name is the same and the email is the same as that record. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-10-18 : 08:00:02
|
[code]SELECT booking_id, first_name, last_name, email_add, booking_status_idFROM(select t1.booking_id, t1.first_name, t1.last_name, t1.email_add, t1.booking_status_id,COUNT(1) OVER (PARTITION BY t1.email_add) AS Cntfrom [aren1002].[BOOKING]as t1 inner join [aren1002].[BOOKING]as t2 on t1.last_name=t2.last_name and t1.booking_id<>t2.booking_idwhere t1.booking_status_id = 330)tWHERE Cnt > 1[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|