User mysql to get the data in particular order using order by
Posted by: manishmt
on Feb 4, 2011
I recently worked on the project related to improve the website speed. When I analyzed the files I found that it used a lot of php code which can easily replaced by mysql. There were a scenario where we sort the record in particular order e.g. 2,0,1 and it was accomplished with the help of PHP code.
When I checked the mysql manual I found it can be done easily using ORDER BY FIELD
For e.g. If you have 3 priorities Low, Normal, High and you want to display High records first and then Normal and then Low. We used below query for that and it worked very well and it improved the website loading time.
Select * from table_name ORDER BY FIELD(priority_record, ‘High’,’Normal’,’Low’);


