Solved

Query two databases for duplicate entries

Posted on 2007-04-10
4
1,115 Views
Last Modified: 2013-11-15
I have two SQL databases.  One is for Candidates and one is our Main database.  We have a sp that transfers a Candidate into our Main database once we make contact with them and then deletes them from the Candidate database.  Problem is, our sp to delete from the Candidate database is not working - so we have duplicate entries in both databases.

I need a query so I can look for duplicates in both databases.
Database 1 - CandSource  Table - Contact1
Database 2 - Goldmine   Table - Contact1

output to delimited file.
I know this is easy for a SQL god...but I am not one...
Thank you thank you.  
0
Comment
Question by:NetzillaKB
[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
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
soco180 earned 500 total points
ID: 18884877
First you are going to have to define what a duplicate is...In the below query I assumed a duplicate means a person with the same last name and same first name. That is very loose logic. You might want to include city, state and zip.

How do you define a duplicate?

SELECT *
FROM CandSource..Contact1 C
INNER JOIN GoldMine..Contact1 G
    ON C.ContactLastName = G.ContactLastName
    AND C.ContactFirstName = G.ContactFirstName
0
 

Author Comment

by:NetzillaKB
ID: 18884933
the duplicate would be the name only.  Frequently, while making contact with the candidate, the recruiter updates their city,state, or zip and then they wouldn't be duplicates.

Thanks.  I'll see if this works...KB
0
 

Author Comment

by:NetzillaKB
ID: 18885007
I had to tweak the table names a little, but I'm getting an output to the screen.  How can I see which database the entry CAME from?  And how can I get the output to a delimited file?
0
 
LVL 2

Expert Comment

by:soco180
ID: 18885124
Another question, do you have a Primary Key such as an Identity column on the Candidate DB? It might be easier for you to script you Delete statement.

As for the delimited part: Are you using MS SQL Query Analyzer or MS SQL Server Managment Sudio 2005 or something else?

I tried to clear that up below by only selecting contacts from you Candidate database (which are also in the GoldMine DB).

SELECT C.ContactLastName + ',' + C.ContactFirstName AS Name
FROM CandSource..Contact1 C
INNER JOIN GoldMine..Contact1 G
    ON C.ContactLastName = G.ContactLastName
    AND C.ContactFirstName = G.ContactFirstName
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

751 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