How about I have a table students with a column called " id_schools " in Mysql I want it is to make a "select" that throw me the results ordered as follows:
nombre_a id_escuelas
--------- -------------
Juan 1
Roman 2
Raul 3
Omar 1
Jose 2
I found in the following link ( link ) A piece of code that adapts it to my table in the following way:
SELECT x.id_escuelas,
x.nombre_a
FROM (SELECT alumnos.id_escuelas,
alumnos.nombre_a,
CASE
WHEN @id_escuelas != alumnos.id_escuelas THEN @rownum := 0
WHEN @id_escuelas = alumnos.id_escuelas THEN @rownum := @rownum + 1
ELSE @rownum
END AS rank,
@id_escuelas := alumnos.id_escuelas
FROM TABLE alumnos,
(SELECT @rownum := 0, @id_escuelas
ORDER BY alumnos.id_escuelas) r) x
ORDER BY x.rank, x.id_escuelas
Thank you in advance