0

I am familiar with basic usage of 'load data local infile' and importing specific columns only. What I want is however to import a single column from file based/related on data from another column. So if I have say a table with column names 'name' 'value' 'value1'... and a file with 'name' 'value1', can I load only 'value1' column which corresponds to 'name'? Note that 'name' in file is not ordered.

Existing table:

name|value|value1

Peter, 5, ferrari

Alice, 2, fiat

John, 2, pontiac

File values:

name, value1

John, vw

Peter, chevy

Alice, fiat

Something like: LOAD DATA LOCAL INFILE "/home/file.csv" replace into table mytable fields terminated by "," optionally enclosed by '"' (@dummy,value1) where name=@col1;

Is there some way to do it?

  • 1
    I think you should load the file into a new, temporary table, then update mytable using this temp table. – ypercubeᵀᴹ Aug 10 '14 at 12:09
  • Thanks. I indeed used 'update' using a script to achieve what I wanted. Pitty there is no direct way to do it in mysql as it seems. – Senad Aug 11 '14 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.