0

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.

  • Please show your data, your schema and what you really want to try to achieve. "order like 4,3,2,1,5" looks completely random. – Bart Friederichs Jan 29 '14 at 07:33
  • you need some field you can sort with. some column which would help you to fetch in that order – Furquan Khan Jan 29 '14 at 07:35
  • This should be your answer [php mysql sort results by order fetched](http://stackoverflow.com/questions/12459816/php-mysql-sort-results-by-order-fetched/12459958#12459958) – Rahil Wazir Jan 29 '14 at 07:51

4 Answers4

2

you can use FIELD in order clause

order by FIELD(field_name,4,3,2,1,5)
naveen goyal
  • 4,571
  • 2
  • 16
  • 26
1

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

Community
  • 1
  • 1
Furquan Khan
  • 1,586
  • 1
  • 15
  • 30
0

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

Dinuka Thilanga
  • 4,220
  • 10
  • 56
  • 93
0

Try this,

SELECT table.* FROM table  ORDER BY FIELD(id,4,3,2,1,5);
Krish R
  • 22,583
  • 7
  • 50
  • 59