Page 1 of 1

Select from middle rows of database in descending order

Posted: Mon Jun 22, 2009 11:41 pm
by atyler
I want to select multiple rows from the middle of the database in descending order.

I am aware of using

Code: Select all

SELECT field FROM table ORDER BY id DESC LIMIT x
to pull the last x number of rows, and

Code: Select all

SELECT field FROM table LIMIT y,z
to pull z rows starting with row y.

However, I need to be able to "combine" these so I can pull x rows starting with row y and most importantly, I need the data in descending order.

Can anyone recommend the best way to accomplish this?

Thanks for the help!

AT

Re: Select from middle rows of database in descending order

Posted: Tue Jun 23, 2009 1:45 am
by VladSun
Use subselect:
[sql]SELECT * FROM ( SELECT ....) AS my_subselect_table ORDER BY ....[/sql]

Re: Select from middle rows of database in descending order

Posted: Tue Jun 23, 2009 10:40 am
by atyler
Great. Thank you!

AT