Select from middle rows of database in descending order

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
atyler
Forum Newbie
Posts: 17
Joined: Tue May 26, 2009 10:28 pm

Select from middle rows of database in descending order

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Select from middle rows of database in descending order

Post by VladSun »

Use subselect:
[sql]SELECT * FROM ( SELECT ....) AS my_subselect_table ORDER BY ....[/sql]
There are 10 types of people in this world, those who understand binary and those who don't
atyler
Forum Newbie
Posts: 17
Joined: Tue May 26, 2009 10:28 pm

Re: Select from middle rows of database in descending order

Post by atyler »

Great. Thank you!

AT
Post Reply