Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Eliminate Duplicates in SQL

Posted on 2013-01-17
4
Medium Priority
?
279 Views
Last Modified: 2013-01-17
Hello, I have got the following SQL Query which gives me the list of birthdays in a month.
it is coming up with some Duplicates, how can I get rid of those, and it also comes up with a record called Admin User which I would like to eliminate as well.
  select   e.given_name +' '+e.surname as full_name
  from dbo.q2employees e 
  where MONTH(e.[date_of_birth]) = MONTH(GETDATE())
  

Open in new window


Thanks
0
Comment
Question by:jhonc66
[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
4 Comments
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 1000 total points
ID: 38790796
select  distinct  e.given_name +' '+e.surname as full_name
  from dbo.q2employees e
  where MONTH(e.[date_of_birth]) = MONTH(GETDATE())
0
 
LVL 23

Accepted Solution

by:
Steve Wales earned 1000 total points
ID: 38790801
You can use the DISTINCT key word to eliminate duplicates from a result set.

Then you add an extra AND to refine out Admin User.  Assuming that Admin is the first name and User the last name you'd do:
select   DISTINCT e.given_name +' '+e.surname as full_name
from dbo.q2employees e 
where MONTH(e.[date_of_birth]) = MONTH(GETDATE())
and not (e.given_name = 'Admin' and e.surname = 'User')

Open in new window

0
 
LVL 39

Expert Comment

by:appari
ID: 38790802
are you sure they are duplicates? may be different employees with same name.
try

select   distinct e.given_name +' '+e.surname as full_name, e.[date_of_birth]
  from dbo.q2employees e
  where MONTH(e.[date_of_birth]) = MONTH(GETDATE())
0
 

Author Closing Comment

by:jhonc66
ID: 38790897
Excelent
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

609 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