Answer the question
In order to leave comments, you need to log in
UPDATE + JOIN + ORDER BY in one query?
There is a table dsl_checkins and area_distance . In area_distance 3 fields :
distance
area1
area2
distance = 3456
area1 = phoenix
area2 = houston
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;
Error Code: 1221. Incorrect usage of UPDATE and ORDER BY
UPDATE Ratemaster
SET Ratemaster.Rate =
(
SELECT Rates.Rate
FROM Rates
WHERE Ratemaster.user = Rates.user
ORDER BY Rates.id
LIMIT 1
)
Answer the question
In order to leave comments, you need to log in
I don't understand this line. Do you sort or randomize?ORDER BY AD.distance ASC, RAND()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question