Reputation: 9289
I have this SQL query:
SELECT * FROM teams ORDER BY team_name
This will give the teams in the table as result, ordered by the team's name. But how to move an element to the beginning of the list?
I would like to have Manchester United
at the first row, and the other teams after that in alphabetical order.
Upvotes: 0
Views: 40
Reputation: 4192
Split the query, and then add back together with a Union Query:
SELECT * FROM teams WHERE team_name="Manchester United"
UNION
SELECT * FROM teams WHERE team_name NOT LIKE "Manchester United" ORDER BY team_name
Upvotes: 1
Reputation: 661
What you could do is add an extra field, IF(team_name='Machester United', 1, 2) AS team_one
and then do your ORDER BY like this: ORDER BY team_one, team_name
Upvotes: 3