Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
How to write a query to look for matches between the tables in SQL?
Old 02-10-2010, 01:30 PM How to write a query to look for matches between the tables in SQL?
Skilled Talker

Posts: 53
Name: Wizzy
Trades: 0
I need some help with writing an SQL query.

I have 2 tables with some duplicate data that I would like to associate with each other.
Table1 - ID-Group1
ID - primary key
FirstName
LastName
Address
City
State
Zip


Table2 - IDGroup2
ID - primary key
FirstName
LastName
Address
City
State
Zip
Table1ID



There are a large number of duplicate Firstname/lastName/add/city/state/zip in Table1 and Table2, but they have different ID's.

Is there a way to write a query to look for matches between the tables and then update Table1ID on the appropriate Table2 record?

thanks
virtualmisc is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-10-2010, 02:19 PM Re: How to write a query to look for matches between the tables in SQL?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
which db are you using ? Mysql, postgresql, ms sql server, oracle, db2 ? And I am not sure I understand you correctly ? You want to copy the id of the 1st table to the second when the names match? Or do you want to sync the names/addresses for a given id if they are different ?
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 02-10-2010 at 02:26 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-27-2010, 12:00 PM Re: How to write a query to look for matches between the tables in SQL?
Experienced Talker

Posts: 34
Trades: 0
Update IDGroup2 Set Id = IDGroup1.Id from IdGroup1
Where IdGroup1.FirstName = IDGroup2.FirstName AND
IdGroup1.LastName = IdGroup.LastName

And you can add more conditions.
__________________
World's leading
Please login or register to view this content. Registration is FREE
. All free now.


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
robert1971 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to How to write a query to look for matches between the tables in SQL?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11927 seconds with 12 queries