Database IntegrationLesson 57Free preview
MySQL Limit
This lesson is part of Node.js · All levels
Summary
This lesson discusses the LIMIT clause on MySQL queries in Node.js to limit the number of result rows. LIMIT is critical when displaying a list of data so as not to flood the memory of the application. You also learn the combination of LIMIT and OFFSET to create pages of data.
Key points
- Limit n limits the query results to n lines only.
- LIMIT offset, count or LIMIT count OFFSET offset is used for pagination.
- Always use ORDER BY with LIMIT to make the sequence of results consistent between queries.
- The combination WHERE + ORDER BY + LIMIT is a basic pattern of reading limited data.
- Queries with LIMIT are more memory-efficient because the drivers don't accommodate the entire table line.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.