简体   繁体   中英

How to select set of data from a table from nth row to 1st row

I have written a query to select set of data from nth to last record like below

select station_code from route_master where route_code = "102D" and sequence_no limit "5", "100";
  • table name: route_master
  • column name: route_code

Now I want to select data from nth to 1st row.

You can just use a plain LIMIT command along with a subquery which imposes the reverse ordering:

SELECT station_code
FROM
(
    SELECT station_code, sequence_no
    FROM route_master
    WHERE route_code = '102D'
    ORDER BY sequence_no
    LIMIT n
) t
ORDER BY sequence_no DESC;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM