Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing two tables for matching items 1

Status
Not open for further replies.

DrumAt5280

Technical User
Sep 8, 2003
194
US
I have two DB tables, one table has a complete list of street names and the other has partial list of street names - I would like to make sure that each street name in the Partial list has a matching entry in the Complete list.

Because i have thousands of street names how can i automate this matching process with the two tables?

Here is what i am thinking (I will be using Coldfusion):

I create a loop,
Inside this loop i query the first item in the Partial list,
Assign the returned record to a variable such as "Partial-result",
Then query the Complete list to see if it matches the "Partial-result" variable - if it does start the loop process again - if not then write that variable to a new table called "NoMatch" and start the loop again.

Does this logic above seem to be the best way to do it?

Thanks!


 
It's simpler than you might think! How about:
[tt]
SELECT partiallist.streetname
FROM
partiallist
LEFT JOIN completelist USING (streetname)
WHERE completelist.streetname IS NULL
[/tt]
 
Cool, so it looks like i don't have to do a loop at all by just using a LEFT JOIN - cool!

Oh, wait - it looks like that the query above is still within a loop - is that correct?
 
It's a single query, which returns at once all the non-matching records. It's then up to your program to process all the records.
 
Wow, i just used the query and it worked great. Thanks and you saved me a ton of time doing it by hand.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top