SQL TutorialLesson 14Free preview
SQL Select Top
This lesson is part of SQL · All levels
Summary
SELECT TOP limits the number of lines the query returns, usually combined with ORDER BY to take the top score. Note that TOP is a special syntax of SQL Server and MS Access; in MySQL the used is the LIMIT clause. The goal is the same, which is to take just a few lines of results.
Key points
- TOP limits the number of result lines; in MySQL use LIMIT.
- MySQL form: SELECT... ORDER BY... LIMIT n;
- LIMIT also supports offsets, for example LIMIT 5 OFFSET 10 for pagination.
- TOP or LIMIT without ORDER BY does not guarantee which line is taken.
- The TOP percent form is only in SQL Server, not in MySQL.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.