importing a CSV into phpmyadmin

后端 未结 4 1281
情深已故
情深已故 2020-11-29 08:25

I have a CSV that looks like this,

candidate_id,show_on_site,first_name,surname,gender,DOB,showdob,Location,height,eyes,hair_colour,hair_length,accents,union         


        
4条回答
  •  执笔经年
    2020-11-29 08:43

    Using the LOAD DATA INFILE SQL statement you can import the CSV file, but you can't update data. However, there is a trick you can use.

    • Create another temporary table to use for the import
    • Load onto this table from the CSC

      LOAD DATA LOCAL INFILE '/file.csv'
      INTO TABLE temp_table
      FIELDS TERMINATED BY ','
      LINES TERMINATED BY '\n'
      (field1, field2, field3); 
      
    • UPDATE the real table joining the table

      UPDATE maintable
      INNER JOIN temp_table A USING (field1)
      SET maintable.field1 = temp_table.field1
      

提交回复
热议问题