Distinct Query to find duplicates (diff primary key)

Vexorg

Board Regular
Joined
Oct 5, 2010
Messages
116
<TABLE cellSpacing=0 bgColor=#ffffff border=1><CAPTION><TABLE cellSpacing=0 bgColor=#ffffff border=1><CAPTION>Hi,
Im having trouble making a query that can find the duplicates like below. The problem is that they have different primary keys, but they have the same fields else. My only guess for this was something similar to

Rich (BB code):
Rich (BB code):
Rich (BB code):
Rich (BB code):
Select DISTINCT core.[Entity ID], core.[First], core.[Last], core.[Email1] from Table1
Rich (BB code):
Rich (BB code):
Where (((core.Email1)>"1")) 


Table1



</CAPTION><THEAD><TR><TH borderColor=#000000 bgColor=#c0c0c0>Entity ID</TH><TH borderColor=#000000 bgColor=#c0c0c0>First</TH><TH borderColor=#000000 bgColor=#c0c0c0>Last</TH><TH borderColor=#000000 bgColor=#c0c0c0>Email</TH></TR></THEAD><TBODY><TR vAlign=top><TD borderColor=#d0d7e5 align=right>1000</TD><TD borderColor=#d0d7e5>John</TD><TD borderColor=#d0d7e5>Smith</TD><TD borderColor=#d0d7e5>jsmith1@gmail.com</TD></TR><TR vAlign=top><TD borderColor=#d0d7e5 align=right>2000</TD><TD borderColor=#d0d7e5>John</TD><TD borderColor=#d0d7e5>Smith</TD><TD borderColor=#d0d7e5>jsmith1@gmail.com</TD></TR><TR vAlign=top><TD borderColor=#d0d7e5 align=right>3000</TD><TD borderColor=#d0d7e5>Sally</TD><TD borderColor=#d0d7e5>Mae</TD><TD borderColor=#d0d7e5>sm@asdf.com</TD></TR><TR vAlign=top><TD borderColor=#d0d7e5 align=right>4000</TD><TD borderColor=#d0d7e5>Howard</TD><TD borderColor=#d0d7e5>H</TD><TD borderColor=#d0d7e5>adfasd@adfs.com</TD></TR></TBODY><TFOOT></TFOOT></TABLE></I>

I would like the answers to return:


Table1



</CAPTION></I><THEAD><TR><TH borderColor=#000000 bgColor=#c0c0c0>Entity ID</TH><TH borderColor=#000000 bgColor=#c0c0c0>First</TH><TH borderColor=#000000 bgColor=#c0c0c0>Last</TH><TH borderColor=#000000 bgColor=#c0c0c0>Email</TH></TR></THEAD><TBODY><TR vAlign=top><TD borderColor=#d0d7e5 align=right>1000</TD><TD borderColor=#d0d7e5>John</TD><TD borderColor=#d0d7e5>Smith</TD><TD borderColor=#d0d7e5>jsmith1@gmail.com</TD></TR><TR vAlign=top><TD borderColor=#d0d7e5 align=right>2000</TD><TD borderColor=#d0d7e5>John</TD><TD borderColor=#d0d7e5>Smith</TD><TD borderColor=#d0d7e5>jsmith1@gmail.com</TD></TR></TBODY><TFOOT></TFOOT></TABLE>


Can anyone help? Sorry for the weird formatting!
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Code:
select 
  core.*
from
  core
inner join 
  (
    select 
      core.Email
    from
      core 
    group by 
      core.Email
    having 
      count (*) > 1
  ) as dups
  on 
    core.email = dups.email
 
Upvote 0
is the name of your field email or email1 ?

dups is just an alias for a subquery

you could just as easily take out the
Code:
   select 
      core.Email
    from
      core 
    group by 
      core.Email
    having 
      count (*) > 1
save it as its own query, call it dups
and then make a 2nd query which joins to the first query
Code:
select 
  core.*
from
  core
inner join 
  dups
  on 
    core.email = dups.email
but instead of making 2 queries, I just like to put it all together
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,909
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top