0

I have the following simple query:

SELECT * FROM grade order by GRADENAME

It outputs:

enter image description here

This is a problem mostly on the user experience part, Since he received the grades on the <select></select> element as the list above shows. Is there a way I can order them to show starting from 1A all the way to 11D? Is there a possible way to do it?

EDIT

Applying SELECT * FROM grade order by BIN(GRADENAME);

results in:

enter image description here

CodeTrooper
  • 1,890
  • 6
  • 32
  • 54

3 Answers3

1

Try this

SELECT * FROM grade order by BIN(GRADENAME);
Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
1

May be something like this

SELECT * FROM grade 
Order By Cast(SubString(GRADENAME,1,Length(GRADENAME) -1 As Int),Right(GRADENAME,1)

Or

SELECT * FROM grade 
Order By lpad(GRADENAME, 10, 0)
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115
  • This does work as well. But it has more code than `SELECT * FROM grade order by lpad(GRADENAME, 10, 0)`. I will stay with the one I found. Thanks for your answer though. – CodeTrooper Jul 07 '14 at 09:33
0

Try this

SELECT GRADEID, 
       GRADENAME 
FROM   GRADE 
GROUP  BY GRADENAME 
ORDER  BY 2; 
Gidil
  • 4,137
  • 2
  • 34
  • 50
RSB
  • 359
  • 5
  • 10