0

Question is almost similar to Check if records exists in a Postgres table but in my case, i don't have any unique column. Currently i'm adding records from csv to mysql using php with this query:

"LOAD DATA LOCAL INFILE '".$file."' INTO TABLE $table FIELDS TERMINATED BY '$fieldSeperator' ";

where $file is csv file, $table is name of table and $fieldSeperator is , or \t

But the above query can only add new record without comapring to previous. How to check for rows if they dont exist then add new else no change?

7
  • you will have to open the file and loop to process it, you wont be able to use LOAD DATA if you need row by row processing Commented Mar 30, 2014 at 19:48
  • @Dagon is there any solution like stackoverflow.com/a/12756520/2037323 ? Commented Mar 30, 2014 at 19:49
  • from what i understand of your question, no. Commented Mar 30, 2014 at 19:49
  • I asked @erwin-brandstetter about that but was not able to understand that, he replied: Join on enough columns to make it unique. All columns if you have to. The USING or the NATURAL clause would come in handy for that. Normally, every table should have a primary key, though Commented Mar 30, 2014 at 19:52
  • 1
    or may be to create a temp table and then compare both tables and then add? Commented Mar 30, 2014 at 19:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.