?
Solved

Eliminate Duplicates in SQL

Posted on 2013-01-17
4
Medium Priority
?
277 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 22

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

762 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