i want sort mysql-table
select id,name tbl order name asc; returns
1 name1 2 name2 4 name3 5 name4 8 name5 how order e.g name 3 goes end of table like
select id,name tbl order ["name name3????"],name asc; returns
1 name1 2 name2 5 name4 8 name5 4 name3 thank you
with case can return value based on condition. can return 1 name3 , 0 other names. sort on value put name3 in back. secondary sort value name, other names still sorted alphabetically.
select id, name tbl order case when name = 'name3' 1 else 0 end, name strawberry taught me in comment use function field accomplish this. handy , more compact, if want specify specific sort number of names. using case become bulky. field returns index of first string in list of other strings, field(name, 'name3', 'name4') return 1 'name3' , 2 'name4' , 0 other names.
your query this:
select id, name tbl order field(name, 'name3'), name
Comments
Post a Comment