Brug:
SELECT x.client_id,
x.project_id,
x.project_name
FROM (SELECT t.client_id,
t.project_id,
t.project_name,
CASE
WHEN @client_id != t.client_id THEN @rownum := 0
WHEN @client_id = t.client_id THEN @rownum := @rownum + 1
ELSE @rownum
END AS rank,
@client_id := t.client_id
FROM TABLE t,
(SELECT @rownum := 0, @client_id
ORDER BY t.client_id) r) x
ORDER BY x.rank, x.client_id
MySQL har ikke nogen ranking-funktionalitet, men heldigvis kan du bruge variabler. Nøglen nulstillede @rownum-værdien, når client_id'et ikke matcher det tidligere client_id - ORDER BY i underforespørgslen er for at sikre, at klienterne er i orden.