3

I want to order the role of the members. Like :

Leaders 
Co Leaders
Elders
Members

But when I use ORDER BY, it orders according to the alphabet. That is :

Co Leaders
Elders 
Leaders
Members

Is it possible to do the sorting like that?

1
  • 2
    Add a weigth field to your table Commented Jan 10, 2015 at 17:53

3 Answers 3

3

You can try to ORDER with FIELD :

ORDER BY FIELD(your_field, 'Leaders' , 'Co Leaders', 'Elders', 'Members')
Sign up to request clarification or add additional context in comments.

Comments

0

Add a column as sort_order int(10) default 0 ;

Now put the value like sort_order = 0 where member_role = Leaders, 1 for Co Leaders and else.

then ORDER BY sort_order

Comments

0

Use can also use Case statement to custom the order.

order by case columnname 
              when 'Leaders' then 1 
              when 'Co Leaders' then 2
              when 'Elders' then 3
              when 'Members' then 4
         End

4 Comments

@Strawberry - sorry didn't get you.
What advantage does this offer over FIELD()
@Strawberry This is just another way of doing it nothing wrong in posting another answer.
I'm not suggesting there is, am I?? Just wanted to know :-(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.