MySQL - UPDATE query based on SELECT Query

后端 未结 11 2329
既然无缘
既然无缘 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:44

    If somebody is seeking to update data from one database to another no matter which table they are targeting, there must be some criteria to do it.

    This one is better and clean for all levels:

    UPDATE dbname1.content targetTable
    
    LEFT JOIN dbname2.someothertable sourceTable ON
        targetTable.compare_field= sourceTable.compare_field
    SET
        targetTable.col1  = sourceTable.cola,
        targetTable.col2 = sourceTable.colb, 
        targetTable.col3 = sourceTable.colc, 
        targetTable.col4 = sourceTable.cold 
    

    Traaa! It works great!

    With the above understanding, you can modify the set fields and "on" criteria to do your work. You can also perform the checks, then pull the data into the temp table(s) and then run the update using the above syntax replacing your table and column names.

    Hope it works, if not let me know. I will write an exact query for you.

提交回复
热议问题