Solved

Query two databases for duplicate entries

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sql query 7 36
Pivot not using aggregate yield error 3 20
SQL BACKUP - 2008 R2 8 17
Split Data in 1 column into 2 columns 8 21
Read about achieving the basic levels of HRIS security in the workplace.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

760 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

18 Experts available now in Live!

Get 1:1 Help Now