(SELECT * FROM atable WHERE username = 'John')
UNION ALL
(SELECT * FROM atable WHERE username <> 'John' ORDER BY username)
Or more general:
(SELECT * FROM atable ORDER BY username DESC LIMIT 1)
UNION ALL
(SELECT * FROM atable WHERE id NOT IN (
SELECT id FROM atable ORDER BY username DESC LIMIT 1)
ORDER BY username)
If you have to avoid combining for any reason, this slow code will also work:
SELECT * FROM atable
ORDER BY
CASE WHEN id IN (SELECT id FROM atable ORDER BY username DESC LIMIT 1)
THEN 0 ELSE 1 END
, username
In SQL Server, the syntax is slightly different, the subquery:
SELECT TOP 1 id FROM atable ORDER BY username DESC
Johan source
share