watsmyname Posted October 25, 2010 Share Posted October 25, 2010 Greetings, I have to fetch numbers of row in ascending order. However my problem is that among these rows i want one row to appear always at top and rest in ascending order. For example, i want the row with id 17 to be appeared always on top . I know this can be achieved with two different sql statements. First display row with id 17, and next loop through the other rows. However i want to achieve this with a single sql statement. Is it possible?? Thanks Watsmyname Quote Link to comment https://forums.phpfreaks.com/topic/216748-how-to-show-particular-row-always-at-first/ Share on other sites More sharing options...
OldWest Posted October 25, 2010 Share Posted October 25, 2010 Would you mind shedding some light on exactly why you want one specific row to be on top? Is it only row 17? Can you describe more the context and purpose of this? Quote Link to comment https://forums.phpfreaks.com/topic/216748-how-to-show-particular-row-always-at-first/#findComment-1126070 Share on other sites More sharing options...
watsmyname Posted October 25, 2010 Author Share Posted October 25, 2010 thanks, well id 17 is just an example, the row to show at first depends upon id that comes from query string. well i got a solution for this select * from table_name order by field(id,'17') DESC Quote Link to comment https://forums.phpfreaks.com/topic/216748-how-to-show-particular-row-always-at-first/#findComment-1126071 Share on other sites More sharing options...
watsmyname Posted October 25, 2010 Author Share Posted October 25, 2010 well i solve it but however i ran into problem. I have to show that particular id on the top, and rest should be sorted date wise. I changed the code to select * from table_name order by field(id,'17'),created_date DESC But this yielded an unpleasant result. It sorted all the rows by "created_date" ignoring first part of sort condition. And "Mark Unsolved" Button is not working as well! Quote Link to comment https://forums.phpfreaks.com/topic/216748-how-to-show-particular-row-always-at-first/#findComment-1126082 Share on other sites More sharing options...
watsmyname Posted October 25, 2010 Author Share Posted October 25, 2010 Well thanks guys, i got it work select * from table_name order by field(id,'17') DESC, created_date DESC Quote Link to comment https://forums.phpfreaks.com/topic/216748-how-to-show-particular-row-always-at-first/#findComment-1126097 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.