Q:

MYSQL order by text

okay so I know how I can sort by id or number like
$getTicket = $sql->query("SELECT * FROM `ticket` 
                          WHERE `user`='$user->name' 
                          ORDER BY `id` DESC");

I have Status in the ticket table, and in that I have 3 things: 
1) Answered 2) Unanswered 3)  Done
I want to sort it in this way:
1) Unanswered
2) Answered
3) Done
is there a way to do this?

A:

Do simple as-
ORDER BY FIELD(Status, 'Unanswered', 'Answered', 'Done')

A:

You can generally use case
SELECT * FROM `ticket` 
WHERE `user` = '$user->name' 
ORDER BY case when Status = 'Unanswered' then 1
              when Status = 'Answered' then 2
              else 3
         end

or MySQL specific find_in_set
SELECT * FROM `ticket` 
WHERE `user` = '$user->name' 
ORDER BY find_in_set(Status, 'Unanswered,Answered,Done')

