How to update from select with a Join

后端 未结 2 984
谎友^
谎友^ 2020-12-11 15:22

How can I update a table that is also present in a subquery? Do I have to do it in 2 stages? (create a temporary table - put the selected data in it and then update the fina

相关标签:
2条回答
  • UPDATE invoiceLine SET network = (
        SELECT label FROM network WHERE id = (
            SELECT network FROM terminal WHERE terminal.ctn = invoiceLine.ctn
        )
    )
    
    0 讨论(0)
  • 2020-12-11 15:48
    UPDATE invoiceLine
        INNER JOIN terminal
            ON invoiceLine.ctn = terminal.ctn
        INNER JOIN network
            ON terminal.network = network.id
        SET invoiceLine.network = network.label
    
    0 讨论(0)
提交回复
热议问题