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.

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?

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?

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?

SELECT * FROM TableName ORDER BY colunamnName ASC / DESC ;

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;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.