lopes_andre Posted October 22, 2008 Share Posted October 22, 2008 Hi, I need to insert to my email database new emails in CSV format, but I don't want to import duplicate emails. Table Scheme: id | email (unique) | name --------------------------- 1 | expl1@mail.com | expl1 2 | expl2@mail.com | expl2 3 | expl3@mail.com | expl3 4 | expl4@mail.com | expl4 How can I import to this database new emails without insert duplicate emails? The function LOAD DATA INFILE can do this, avoiding to insert duplicate emails in the UNIQUE field "email"? Best Regards, André. Quote Link to comment https://forums.phpfreaks.com/topic/129548-avoid-insert-duplicate-emails-when-importing-from-csv-file/ Share on other sites More sharing options...
php.ajax.coder Posted October 22, 2008 Share Posted October 22, 2008 You can use the email field as a primary key this prevents the same email being entered twice. Quote Link to comment https://forums.phpfreaks.com/topic/129548-avoid-insert-duplicate-emails-when-importing-from-csv-file/#findComment-671712 Share on other sites More sharing options...
lopes_andre Posted October 22, 2008 Author Share Posted October 22, 2008 Hi, Thanks for your reply. I don't explain me well. The email field is "unique", but I need to import data to this database and I know that some emails that I will import are duplicated, but because the field email is "unique" I think the import will stop with an error every time that one duplicate email is inserted(or tried to insert). What I need to know is... there is some way do to this: "if email allready in database, ignore that email and continue importing". There is a way to do this, some mysql function? Best Regards, André. Quote Link to comment https://forums.phpfreaks.com/topic/129548-avoid-insert-duplicate-emails-when-importing-from-csv-file/#findComment-671721 Share on other sites More sharing options...
fenway Posted October 22, 2008 Share Posted October 22, 2008 You can use INSERT IGNORE. Quote Link to comment https://forums.phpfreaks.com/topic/129548-avoid-insert-duplicate-emails-when-importing-from-csv-file/#findComment-672046 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.