MySQL - UPDATE query based on SELECT Query

后端 未结 11 2324
既然无缘
既然无缘 2020-11-21 23:58

I need to check (from the same table) if there is an association between two events based on date-time.

One set of data will contain the ending date-time of certain

11条回答
  •  我在风中等你
    2020-11-22 00:55

    You can update values from another table using inner join like this

    UPDATE [table1_name] AS t1 INNER JOIN [table2_name] AS t2 ON t1.column1_name] = t2.[column1_name] SET t1.[column2_name] = t2.column2_name];
    

    Follow here to know how to use this query http://www.voidtricks.com/mysql-inner-join-update/

    or you can use select as subquery to do this

    UPDATE [table_name] SET [column_name] = (SELECT [column_name] FROM [table_name] WHERE [column_name] = [value]) WHERE [column_name] = [value];
    

    query explained in details here http://www.voidtricks.com/mysql-update-from-select/

提交回复
热议问题