Solved

Eliminate Duplicates in SQL

Posted on 2013-01-17
4
268 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
4 Comments
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 250 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 250 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

810 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