Solved

Query two databases for duplicate entries

Posted on 2007-04-10
4
1,112 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

776 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