mbouclas
mbouclas

Reputation: 744

mysql load data infile

i got to execute loads of the following queries

UPDATE translations SET translation = (SELECT description FROM content WHERE id = 10) WHERE id = 1;

Now, i use the load data infile to do inserts and replacements but what i want in esense is to update just 1 field for each row in that table with out messing with the keys. What could be the syntax for this, note that the queries affect existing rows only.

Thanx

Upvotes: 3

Views: 1121

Answers (1)

Jason S
Jason S

Reputation: 189676

  • Use CREATE TEMPORARY TABLE to create a temporary table.
  • Then use LOAD DATA INFILE to populate that temporary table.
  • Then execute your UPDATE translations SET translation = ... to set the 1 field from a SELECT of the temporary table, JOINed with the real table. example syntax below:

    UPDATE realTable, tmpTable 
      SET realTable.price = tmpTable.price 
      WHERE realTable.key = tmpTable.key
    

Upvotes: 6

Related Questions