

Welcome to the next installment in our journey of learning SQL. For a quick recap, here’s what we’ve learned recently in SQL:
- The SQL COUNT Function
- The SELECT WHERE SQL Statement
- Using the SQL SELECT Clause with the DISTINCT keyword
Today, we’ll be discussing the LIMIT statement. The LIMIT statement allows you to limit the number of rows you get back after a query. The LIMIT statement is useful when you want to return all the columns in a table, but not return all hundred thousand or so rows. The LIMIT statement will typically be placed at the end of a SQL query.
LIMIT Statement Syntax Examples
Let’s jump in! Here’s our basic syntax example of the LIMIT statement within a SQL query:
Say we’ll continue using the dvd rental sample SQL database, here’s another sample query:
So above, we would call in the first name, last name and email columns from the customer table, and only wanting to get back the first 5 rows. Let’s also take a look at it in pgAdmin.

We can also combine what we’ve learned previously about SELECT DISTINCT statements. Say we want to get the first 10 unique values from a database, say the first 10 unique districts/states in our address SQL table. Take a look below.

More Context About the LIMIT Statement
We covered an obvious application of why we would use the LIMIT statement: you can’t always crash your server pulling down 1 million rows to just get . Duh. But we can also harness the power of SQL by combining LIMIT with other statements. For example, we can use the ORDER BY statement (in an upcoming article) to get the top X or bottom X number of results.
Wrap-Up
This was a quick session! The real power of the LIMIT statement (and other SQL statements) will come as we combine and mash up more granular queries to power through the noise of aggregate data, down to actionable insights. If you need a refresh on previous sections, check out our How to Learn SQL section.
Related
Notes, Legal, Disclaimers
Content and media on this site may not represent the positions of my employer(s), agents, affiliates, subsidiaries, clients and should not be interpreted as such. (The list includes, but is not limited to the aforementioned.)
This site may contain advertising and/or affiliate links.
Sitemap
- Case Studies
- Blog
- Contact
- About
- Experience
- Home
- Education
- #DotyDownTheAisle
- Structured Query Language (SQL)
- Amazon Alexa / Echo Voice Skill Development
- Machine Learning
- SEO
- The Complete SEO Audit
- Digital Marketing Strategy
- Savvy SEO Reporting
- R
- Windows Batch File Commands & Scripting Reference for Marketing