UPDATE Syntax with ORDER BY, LIMIT and Multiple Tables

后端 未结 2 1262
醉酒成梦
醉酒成梦 2020-12-17 01:11

Learning SQL, sorry if this is rudimentary. Trying to figure out a working UPDATE solution for the following pseudoish-code:

UPDATE tableA 
SET          


        
2条回答
  •  自闭症患者
    2020-12-17 01:37

    You can use following query syntax:

    update work_to_do as target
       inner join (
          select w. client, work_unit
          from work_to_do as w
             inner join eligible_client as e on e.client = w.client
          where processor = 0
          order by priority desc
          limit 10
       ) as source on source.client = target.client
          and source.work_unit = target.work_unit
       set processor = @process_id;
    

    This works perfectly.

提交回复
热议问题