In a MySQL query how would I select:
- all rows, ordered by column
name
- those with
name > 'f'
should come first, then the rest alphabetically
so I'd get G, H, …, X, Y, Z, A, B, C …, F
.
In a MySQL query how would I select:
name
name > 'f'
should come first, then the rest alphabeticallyso I'd get G, H, …, X, Y, Z, A, B, C …, F
.
Maybe I'm missing something, but it's
SELECT * FROM mytable WHERE name > 'F' ORDER BY name
You could make a view with 2 select query's
SELECT * FROM mytable WHERE name > 'F' ORDER BY name
and
SELECT * FROM mytable WHERE name < 'F' ORDER BY name
and combine the results
SELECT
*
FROM
mytable
ORDER BY
CASE WHEN name > 'F' THEN 0 ELSE 1 END,
name
I think he wants an answer like
SELECT * FROM mytable WHERE name > 'F' ORDER BY SUBSTR (name, 1, 1) + 'G'
Using MySQL, you can use this shorter code:
SELECT * FROM tbl ORDER BY name > 'F' DESC, name
G,H,I... is greater than F, so the above condition will result to true, true sorts last, false sorts first, so just put DESC