如何不锁定整个桌子?

时间:2016-07-02 14:58:50

标签: mysql

我有两张表dsl_checkinsarea_distance。 在area_distance 3行:

distance
area1
area2

示例:

distance = 3456
area1 = phoenix
area2 = houston

所以我需要从距离最低的dsl_checkins表条目中获取并且需要携带usage_flag字段。我的想法是使用以下查询:

UPDATE dsl_checkins DC
    join area_distance AD
    on AD.area2 = DC.area
set DC.usage_flag=1,
    DC.id = (SELECT @dsl_id := DC.id)
WHERE DC.active = 1 AND
      DC.offline = 0 AND
      usage_flag = 0 AND
      AD.area1 = 'houston'
ORDER BY AD.distance ASC, RAND()
limit 1;

但我收到错误:

  

错误代码:1221。UPDATE和ORDER BY的使用不正确

任何想法如何在没有锁定整个dsl_checkins表的情况下做到这一点?

1 个答案:

答案 0 :(得分:0)