Forum Moderators: coopster

Message Too Old, No Replies

Howto ORDER BY entire table and LIMIT?

         

HoboTraveler

6:34 pm on Sep 6, 2007 (gmt 0)

10+ Year Member



Hi All,

I'm faced with a unique problem. I need to ORDER the contents of the table based on the filename column and at the same time LIMIT the SELECT results to 50.

SELECT ID FROM TABLE ORDER BY filename ASC LIMIT 0,50

The above statement will ORDER the first 50 records only and not the entire table.

Is it possible to ORDER AND LIMIT in one SQL statement? or what is the alternative solution?

PHP5
MySQL4

TIA

Demaestro

6:36 pm on Sep 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I am curious... why does it matter if the rest of the rows are ordered if you are not returning them?

Demaestro

6:45 pm on Sep 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



the thing is is that it does sort the whole table before it gets the first 50 results... that is how it knows what the 0 to 50th elements are.. is by sorting it... remember you are sorting the results and your results only have 50 rows... maybe if you could explain why you are asking this I can be of better help.

HoboTraveler

5:31 am on Sep 7, 2007 (gmt 0)

10+ Year Member



Thanks! You are correct.

It does ORDER the entire table. There was a bug in my script.

Works great now..