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";
route_master
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.