Solved

Eliminate Duplicates in SQL

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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

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…
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

691 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