Mysql load data infile

I need to fulfill the following queries

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

Now I use infile load data to do inserts and replacements, but what I want in esense is to update only 1 field for each row in this table, without triggering the keys. What could be the syntax for this, note that queries only affect existing strings.

Thanx

+3
source share
1 answer
  • Use CREATE TEMPORARY TABLEto create a temporary table.
  • Then use LOAD DATA INFILEto populate this temporary table.
  • Then do yours UPDATE translations SET translation = ...to set field 1 from the SELECT temporary table, JOIN the real table. An example syntax is below:

    UPDATE realTable, tmpTable 
      SET realTable.price = tmpTable.price 
      WHERE realTable.key = tmpTable.key
    
+6
source

Source: https://habr.com/ru/post/1779437/


All Articles