Solved

selecting duplicates AND non duplicates.

Posted on 2007-04-11
3
190 Views
Last Modified: 2007-04-11
I am doing some maintenance on our email user database.  I have the following statement that selects the latest email from the duplicate emails.

SELECT
      EmailAddress,
      MAX(USERID) AS LatestUserID
FROM
      Account
GROUP BY
      EmailAddress
HAVING
      Count(EmailAddress) > 1

What I want to do, is in the SAME statement, select all the emails that are not duplicates. So I have a unique email address on each row.
Thanks in advance
0
Comment
Question by:rbradberry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Expert Comment

by:ksaul
ID: 18891723
SELECT
      EmailAddress,
      MAX(USERID) AS LatestUserID
FROM
      Account
GROUP BY
      EmailAddress
HAVING
      Count(EmailAddress) > 1

UNION

SELECT
      EmailAddress,
      MAX(USERID)
FROM
      Account
GROUP BY
      EmailAddress
HAVING
      Count(EmailAddress) = 1
0
 
LVL 10

Accepted Solution

by:
ksaul earned 500 total points
ID: 18891739
Actually, if I understand it right you can just do:

SELECT
      EmailAddress,
      MAX(USERID) AS LatestUserID
FROM
      Account
GROUP BY
      EmailAddress
0
 
LVL 3

Author Comment

by:rbradberry
ID: 18891900
wow, that seems to have worked out perfectly
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question