Solved

Eliminate Duplicates in SQL

Posted on 2013-01-17
4
265 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now