SQL Update of several lines by one request



  • Hello, I have a table in which there are columns.uname et. Data(s) with values (multi-data) come to the crypt.uname et. We need to update all the poles. u One request. Something like that:

    UPDATE table_name 
    SET colum_name1 = VALUES('value1', 'value2', ..., 'valuenN'),
        colum_name2 = VALUES('value1', 'value2', ..., 'valuenN') 
    WHERE colum_name3 IN ('value1', 'value2', ...,'valuenN');
    


  • I'm afraid that's

    UPDATE table_name
      JOIN (
            select 'val1x' as v1, 'val1y' as v2, 'val1z' as v3
             union
            select 'val2x', 'val2y', 'val2z'
             union
            select 'val3x', 'val3y', 'val3z'
           ) A
        ON A.v3=table_name.colum_name3
    SET colum_name1 = A.v1,
        colum_name2 = A.v2
    

    Or use REPLACE, syntax matching INSERT, provided colum_name3 is the primary or unique key. But the records will be removed and stored, which may have a negative impact on associated tables.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2