How can i include into a mysql select sql a custom sort... for example
A+, A, A-, A-/B+, B+, B, B-, etc.
And also, I would like to alphabetize results from a sql based on the string after a possible (60)... for example:
Hannibal
(60) Hero
Hybrid Theory
MySQL custom sort
Moderator: General Moderators
Store the mark in a seperate table and use a join to get the text. That way your mark's will be INTs, and easily sortable. EG
Code: Select all
Results table:
RESULT_ID NAME
1 A+
2 A
3 A-
4 B+
Marks table:
ID NAME RESULT_ID
1 John Smith 2
2 Fred Bloggs 4
3 Freda Jones 1
SQL:
select m.*, r.name as result_name from marks m left join results r on m.result_id = r.result_id order by m.result_id
ID NAME RESULT_ID RESULT_NAME
3 Freda Jones 1 A+
1 John Smith 2 A
2 Fred Bloggs 4 B+might want to try
Code: Select all
SELECT *
FROM foo
ORDER BY FIELD(column, 'A+', 'A-', 'B+')