Skip to content
Advertisement

query list of users after specified id in sqlalchemy.Table

Letss say that we have 10000 users on this data table.

If the table is ordered by registration_date and I have a user id, how can I query the next 2 users after that id.

e.g if this is the db table and I have the user id 1703, I want to get the next two users in the list.

I tried something like

but I get only the specified user as response

Advertisement

Answer

I’d do something like the following SQL:

In SQLAlchemy, you can do that using a subquery

If you want strict ordering (for example when two people have the exact same registration date), then I’d order by registration_date, id, and use

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement