I have two table dsl_checkins
and area_distance
.
In area_distance
3 rows :
distance
area1
area2
Example:
distance = 3456
area1 = phoenix
area2 = houston
So i need get from dsl_checkins table entry where distance is lowest and need carry about usage_flag
field. My idea was use following query:
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;
but i get error:
Error Code: 1221. Incorrect usage of UPDATE and ORDER BY
Any idea how to do it without lock whole dsl_checkins table?