0

the below table is order by rank .. however i want order by in a way that 'Cpl' comes first. 'lcpl' comes second and 'pte' come last.. if i use ascending or descending it will order by a random manner.

Edited by fire eaters: n/a

Attachments ffff.PNG 5.13 KB
3
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by hericles
0

SELECT * FROM table ORDER BY rank, name asc will order it first by rank (Cpl, Lcpland Pte) and then order by name within each rank. What code were you using to get a random result?

0

well

SELECT * FROM table ORDER BY rank, name asc will order it first by rank (Cpl, Lcpland Pte) and then order by name within each rank. What code were you using to get a random result?

Edited by fire eaters: n/a

0

what if i want to order by all 'Lcpl' first, all 'pte' second, and then all 'Cpl' last

SELECT * FROM table ORDER BY rank, name asc will order it first by rank (Cpl, Lcpland Pte) and then order by name within each rank. What code were you using to get a random result?

-1

As you want it in non-alphabetical order rajeev's post won't help you.
Apparently MySQL has a command that allows you to pick the order of the column's data but I haven't tried it myself.

select * from tablename order by rank='Lcpl' DESC, rank='Pte' DESC, rank='Cpl" DESC;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.