I have table like this one
id name
1 John
2 Mike
3 Zed
4 Teacher
5 Aaron
...........
How to make mysql query to get rows in ASC order by name but put "Teacher" at the top or something that starts with "Teacher"?
select * from your_table
order by case when name = 'Teacher' then 1 else 2 end,
name
MySQLの場合、0
forfalse
および1
for を返すため、次のように機能しますtrue
select * from your_table
order by name <> 'Teacher',
name
select * from table order by case when name like "Teacher%" then 1 else 2 end,name
Teacher で始まる名前がアルファベット順に一番上に表示され、次に残りの名前が表示されます。例
Teacher
Teacher Aaron
Teacher Zed
Aaron
Zed