Question

I have data along with the ids 1,2,3,4,5 but these are not primary ids... I want to fetch data in order like 4,3,2,1,5. I cann't change the ids in database.If i use order by desc it will fetch 5,4,3,2,1.

Was it helpful?

Solution 2

Order by field is one such way:

select * from TABLE order by FIELD(column_name,4,3,2,1,5) ; 

You can look into this for more details:

Field Example

OTHER TIPS

you can use FIELD in order clause

order by FIELD(field_name,4,3,2,1,5)

you can use ORDER BY RAND() for random order.

Try this,

SELECT table.* FROM table  ORDER BY FIELD(id,4,3,2,1,5);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top