Try it this way (assuming that SchoolID
initially IS NULL
)
UPDATE students
SET SchoolID = 1
WHERE SchoolLevel = 'E'
AND SchoolID IS NULL
ORDER BY RAND()
LIMIT 3000;
Then
UPDATE students
SET SchoolID = 2
WHERE SchoolLevel = 'E'
AND SchoolID IS NULL
ORDER BY RAND()
LIMIT 530;
and so on
Here is SQLFiddle example