I have the need to select the last enter for each Passcode for each department. Each department has a 3 digit passcode, each person is given a code based on department. i.e. dept A has numbers 000-099, dept B has 100-199, dept C 201-299 and so on upto 999.
The database holds name and passcode for each person. J smith 101 H frank 102 S saop 301 B Chesse 001 H roberts 401 K robert 402 b brety 403
I need a sorted that should loop over all results and return the last number from each dept (in the above case 102,301, 001, 403)
Not having a lot of joy, should be something like
delimiter #
BEGIN
declare nmax int unsigned default 9;
declare nmin int unsigned default 0;
while nmin < nmax do
select Passcode from main where Passcode < min*100 limit 1;
set nmin = nmin+1;
end while;
END #
delimiter ;
Just throws back 1064 error everytime?