Select last records in ascending order

Asked

Viewed 425 times

2

I know there are many topics with this subject, but none of them have been able to help me so far.

I need to select the last 8 records so that they are organized in ascending order.

Example of the records: 1,2,3,4,5,6,7,8,9,10

Example with the selection: 3,4,5,6,7,8,9,10 (last 8 records).

I tried so SELECT * FROM (tabela) ORDER BY (id) ASC LIMIT 8

Only this way it is selecting from the beginning, that is to say 1,2,3,4,5,6,7,8

1 answer

2

I’ve managed to solve rsrs like this:

SELECT * FROM (SELECT * FROM "tabela" ORDER BY "id" DESC LIMIT 8) AS t1 ORDER BY t1."id"

Remembering that what is between double quotes should be changed according to the table structure...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.