Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

selecting duplicates AND non duplicates.

Posted on 2007-04-11
3
Medium Priority
?
193 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

705 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