Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql Load Data for existing column of a table

Initially I have uploaded Using load Data Infile row is having like 100000 Im Using Ubuntu

Example:data

ToneCode....Artist...MovieName...Language

1....................Mj..........Null........... English

3....................AB..........Null........... English

4....................CD.........Null........... English

5....................EF..........Null........... English

But Now I have To update Column MovieName Starting From ToneCode 1 till 100000 row I’m having data in .csv file to update . Please suggest how to upload the .Csv file for existing table with data

like image 998
vishu Avatar asked Nov 04 '22 01:11

vishu


1 Answers

I think the fastest way to do this, using purely MySQL and no extra scripting, would be as follows:

  • CREATE a temporary table, two columns ToneCode and MovieName same as in your target table
  • load the data from your new CSV file into that using LOAD DATA INFILE
  • UPDATE your target table using the INNER JOIN-like syntax that http://dev.mysql.com/doc/refman/5.1/en/update.html describes:

    UPDATE items,month SET items.price=month.price WHERE items.id=month.id;

    this would “join” the two tables items and month (by using just the “comma-syntax” for an INNER JOIN) using the id column as the join criterion, and update the items.price column with the value of the month.price column.

like image 114
CBroe Avatar answered Nov 05 '22 15:11

CBroe