Advanced MySql Query: Update table with info from another table

前端 未结 3 1497
长发绾君心
长发绾君心 2020-11-29 02:40

I would like to update a table in mySql with data from another table.

I have two tables \"people\" and \"business\". The people table is linked to the business tabl

相关标签:
3条回答
  • 2020-11-29 03:19

    Note, if sort_order is an INT, then don't use '1' - use 1:

    UPDATE business b
    JOIN People p
    ON p.business_id = b.business_id
    AND p.sort_order = '1'
    SET b.email = p.email
    WHERE b.email = '';
    
    0 讨论(0)
  • 2020-11-29 03:32

    Try this, it works fine for me.

    Update table a, table b
    Set a.importantField = b.importantField,
    a.importantField2 = b.importantField2
    where a.matchedfield = b.matchedfield;
    
    0 讨论(0)
  • 2020-11-29 03:37
    UPDATE business b, people p
       SET b.email = p.email
     WHERE b.business_id = p.business_id
       AND p.sort_order = '1'
       AND b.email = ''
    
    0 讨论(0)
提交回复
热议问题