Using the SQL LIMIT clause

When using the LIMIT clause in SQL, if the number in the limit clause is less than the total number of rows, how does it choose which rows to display?

e.g. Say I had 200 rows in the table ‘movies’, which 10 would be returned if I wrote the following query?

SELECT *
FROM movies
LIMIT 10;

The first 10 movies in the movies database would be returned. The database stores the rows by the primary key. If the database has an id column (it likely does), that’s probably the primary key. The movies are given an id when added to the database, and stored in the order they’re entered. If you added an ORDER BY clause to your query, you could get the 10 highest rated, 10 lowest rated, first 10 alphabetically by title, etc. Hope this helps.

1 Like