Next Page After ID 3
Mediumsql
Learn the Concept: Keyset PaginationUsing keyset pagination (not OFFSET), fetch the next page of 3 products after the last-seen id of 3, ordered by id ascending. Return id, name.
sqlCREATE TABLE products ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, category TEXT NOT NULL, price INTEGER NOT NULL );
Sample data:
sqlINSERT INTO products (id, name, category, price) VALUES (1, 'ProLaptop', 'Electronics', 85000), (2, 'Desk Lamp', 'Home', 900), (3, 'ProPhone', 'Electronics', 45000), (4, 'Python Basics', 'Books', 350), (5, 'Novel', 'Books', 220), (6, 'Headphones', 'Electronics', 3000), (7, 'Rug', 'Home', 4500);
Example 1
Input
(none)
Output
id name 4 Python Basics 5 Novel 6 Headphones
Keyset pagination filters WHERE key > lastseenvalue instead of using OFFSET, staying fast regardless of page depth. Reference: SELECT id, name FROM products WHERE id > 3 ORDER BY id ASC LIMIT 3;
Related Problems
- Duplicate EnrollmentsMedium · sqlSolve Problem
- Employees With No Real DepartmentMedium · sqlSolve Problem
- Union: Honors or Dean's ListMedium · sqlSolve Problem