Iter Ator
Iter Ator

Reputation: 9289

Modify order by list, move an element to the top

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

Answers (2)

Sablefoste
Sablefoste

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

marty
marty

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

Related Questions