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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing 2 Tables

Status
Not open for further replies.

Geee

Programmer
Apr 23, 2001
253
GB
Help!

I have a table of users which is updated once a week by the client sending me a spreadsheet, and me uploading the CSV to my scripts which then import the data into the user table. This all works fine. However instead of sending me incremental data that can be just imported, the client has now taken to sending me a complete data list. The problem with this is that I cannot just empty the user table and re-populate with the new data as I will lose the primary key values which I use elsewhere.

My solution to this was to create a new table for importing with the same structure as my user table, import the csv to there, then somehow compare the tables and add the rows missing from the import table into the user table.

My question then, is this possible using a SQL query. Can I compare 2 tables, and add missing data from 1 into the other as new records? I could code a software solution, but with around 30k records in the user table I think a SQL query would be the best approach.

-Geeeeeeeeeeeeeeeeeeeeeeee-
-=
 
Sure, just use "INSERT IGNORE tablename ..." or "LOAD DATA INFILE 'filepath' IGNORE INTO TABLE tablename ...", which will discard any duplicates.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top