Azu Posted September 6, 2007 Share Posted September 6, 2007 Hello How can I make the results be returned backwards without using the super expensive Order By command? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 6, 2007 Share Posted September 6, 2007 The only method I know of in MySQL that allows you to order anything is ORDER BY, so I don't really see how you can escape using it if you want to accomplish this in MySQL. You could, however, use a combination of mysqli_data_seek() and mysqli_ num_ rows() to loop over the record set in reverse. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 7, 2007 Share Posted September 7, 2007 You could, however, use a combination of mysqli_data_seek() and mysqli_ num_ rows() to loop over the record set in reverse. Yes, provided that it's a small enough dataset. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 7, 2007 Share Posted September 7, 2007 Wouldn't a proper index help with ORDER BY? Quote Link to comment Share on other sites More sharing options...
fenway Posted September 8, 2007 Share Posted September 8, 2007 Wouldn't a proper index help with ORDER BY? Yes, but you can't use an index upside down. Quote Link to comment Share on other sites More sharing options...
Azu Posted September 9, 2007 Author Share Posted September 9, 2007 Thanks guys but I don't think any of these solutions will work right. I just want the results to be returned in reverse, that's all. I don't want extra overhead slowing it down. I just wanna flip the results upsidedown. Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 9, 2007 Share Posted September 9, 2007 Just as a matter of interest, do you have any live statistics on the 'super expensive Order By command'? Quote Link to comment Share on other sites More sharing options...
fenway Posted September 9, 2007 Share Posted September 9, 2007 Thanks guys but I don't think any of these solutions will work right. I just want the results to be returned in reverse, that's all. I don't want extra overhead slowing it down. I just wanna flip the results upsidedown. You want the server to "flip the results" but you don't want it to do any extra work?? Quote Link to comment Share on other sites More sharing options...
Azu Posted September 10, 2007 Author Share Posted September 10, 2007 I can't think of any reason for there to be overhead just from returning the results the other way around. And yes Order By is expensive. It makes queries take significantly longer. If you don't want to take my word for it try it yourself or search google for statistics. This is completely besides the point and irrelevant though. All I'm asking is how to return the results backwards. Please tell me how.. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 10, 2007 Share Posted September 10, 2007 Maybe this will help you: http://www.igvita.com/blog/2007/08/20/pseudo-reverse-indexes-in-mysql/ Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 10, 2007 Share Posted September 10, 2007 And yes Order By is expensive. It makes queries take significantly longer. If you don't want to take my word for it try it yourself or search google for statistics. Thanks for the suggestion that I search for myself. Good point! I'll keep it in mind when answering your future questions. Quote Link to comment Share on other sites More sharing options...
Azu Posted September 11, 2007 Author Share Posted September 11, 2007 Thanks roopurt! And I'm sorry andy, I didn't mean it that way.. I'm just saying that I don't want to make a test script just to prove that Order By causes overhead.. I mean doesn't everyone know it causes overhead?? Why do I need to prove that?? Every optimization guide I've read has said so.. No offense.. =\ Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted September 11, 2007 Share Posted September 11, 2007 Of course it causes overhead; any sort operation creates overhead. I think what Andy was getting at was exactly how much overhead is it causing you? 1 ms? 4 s? As another solution, if this is a set of data that doesn't change often, you could always run a cron job in the morning to create a table with the rows in the order you want them and just select from there. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 11, 2007 Share Posted September 11, 2007 If you really want to be fancy, you can issue an alter table statement and sort the whole table,then the rows will be retrieved the way you want them. I can't think of any reason for there to be overhead just from returning the results the other way around. Really? It doesn't "know" how you want your results, YOU told it to be ordered a certain way. If it can figure out a fast way to do it, it will -- otherwise it will take more work. Try and get a card dealer to deal from the bottom of the deck instead, see if it takes any longer. Quote Link to comment Share on other sites More sharing options...
Azu Posted September 12, 2007 Author Share Posted September 12, 2007 Oops forgot to click topic solved. Quote Link to comment 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.