FAQ: Queries - Limit

This community-built FAQ covers the “Limit” exercise from the lesson “Queries”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development
Data Science

Learn SQL

FAQs on the exercise Limit

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

For LIMIT, it doesn’t seem that this command correctly returns data when there is a tie for the final position. For example, for the data set, if you use:

FROM movies
ORDER BY imdb_rating DESC

You return 5 movies as asked, but if you use a large limit you will see that Star Wars and Intersteller are both ranted 8.7 on IMDb. There must be another parameter that breaks the tie-- seems to be id #. How could you change tie-breaking secondary parameters or change the code to return more rows of data in the case of a tie for the final spot to show all movies that tied for this last spot?

SQL Server appears to have a selector to do what you want: SELECT TOP 12 WITH TIES * according to this, but I can’t make it work in the CA version. I’m not sure what the underlying SQL version is that we are dealing with here.

1 Like