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,850
  • 5
  • 31
  • 49

3 Answers3

1

Try this

SELECT * FROM grade order by BIN(GRADENAME);
Sadikhasan
  • 17,858
  • 20
  • 77
  • 117
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
  • 26,868
  • 11
  • 59
  • 105
  • 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,079
  • 2
  • 31
  • 48
RSB
  • 349
  • 5
  • 10