Forum Moderators: coopster

Message Too Old, No Replies

MySQL add only new values

         

planbeta

2:24 pm on Jul 18, 2003 (gmt 0)

10+ Year Member



Hello! :)

If any one can help....I have a text list of emails and I have a script which imports the emails and dumps them in MySQL.

The text list of emails gets updated daily, and would like to modify the script so that when it is run it only adds NEW emails to the db. I would like to do this without having to empty the db first.

Is this possible?

Cheers

Chris

jatar_k

5:05 pm on Jul 18, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would think it depends on how many emails there are in the list. Can you dump/archive the list you are importing from once it it goes into the db? That way you would only have new emails in there.

You could select all the emails load them into an array and then do insert where not in array though it may be faster to delete and just import them all. This again would depend on the amount of data.

The key to the operation is identifying them as new. You need to look at what you have available and thensee what your options are. I am sure there are more than I have mentioned and probably better as well.

DrDoc

6:25 am on Jul 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don't have to empty the table. Just make the email column a primary key. That way no duplicates will be added.

planbeta

11:20 am on Jul 21, 2003 (gmt 0)

10+ Year Member



Thanks DrDoc - perfect solution and SO simple!

Cheers

Chris

killroy

12:44 pm on Jul 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Of course any UNIQUE key will do, if you already have a primary on an ID column or some such.

SN

brotherhood of LAN

9:49 pm on Jul 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



ya UNIQUE, and since youre inserting more than one record at a time are you using this syntax?

INSERT INTO blah (blah) VALUES ('email'),('email'),('email')....

AFAIK thats the best way to insert multiple records, if you are change "INSERT INTO" to "INSERT IGNORE" and it will insert all new records, without having "IGNORE" and if there is a duplicate in the query it will ignore the whole mysql statemnt.