Mode Analytics
Sign In
Sign Up

SQL Editor

Query your connected data sources with SQL

Notebooks

Use Python and R for advanced analysis

Reports

Build customizable, sharable reports


Compare plans Dashboards Security Embedded analytics Customers Integrations

Gallery Learn SQL Learn Python

Mode Business Blog Forum

Mode Analytics

Mode Business
Product

SQL Editor

Query your connected data sources with SQL

Notebooks

Use Python and R for advanced analysis

Reports

Build customizable, sharable reports

Compare plans Dashboards Embedded analytics Customers Integrations Security
Resources

Gallery

Explore example analysis and visualizations

Learn SQL

Answer data questions with SQL

Learn Python

Learn Python for business analysis

Documentation Getting started webinar Forum Blog Contact us
Sign In Sign Up – Free Forever

SQL Tutorial

Basic SQL

  • The SQL Tutorial for Data Analysis
  • Using SQL in Mode
  • SQL SELECT
  • SQL LIMIT
  • SQL WHERE
  • SQL Comparison Operators
  • SQL Logical Operators
  • SQL LIKE
  • SQL IN
  • SQL BETWEEN
  • SQL IS NULL
  • SQL AND
  • SQL OR
  • SQL NOT
  • SQL ORDER BY

Intermediate SQL

Advanced SQL

SQL Analytics Training

Python Tutorial

A complete analytical toolkit, free forever

SQL, Python, R, and built-in charts, all in one place.

Sign Up – Free Forever

SQL LIMIT

Starting here? This lesson is part of a full-length tutorial in using SQL for Data Analysis. Check out the beginning.

Automatic LIMIT in Mode

In Mode’s Query Editor, you may have noticed the checkbox next to “Run” that says “Limit 100”.

As you might expect, the limit restricts how many rows the SQL query returns. The default value is 100; when this box is checked, it’s telling the database to only return the first 100 rows of the query. Because the dataset tutorial.us_housing_units has more than 100 rows, the queries thus far haven’t been returning the full result sets. Try turning the LIMIT off (by clicking the check mark next to it) and running this query.

SELECT *
  FROM tutorial.us_housing_units

You’ll notice many more rows get returned. You can tell by checking the header of the results table:

Why should you limit your results?

Many analysts use limits as a simple way to keep their queries from taking too long to return. The aim of many of your queries will simply be to see what a particular table looks like—you’ll want to scan the first few rows of data to get an idea of which fields you care about and how you want to manipulate them. If you query a very large table (such as one with hundreds of thousands or millions of rows) and don’t use a limit, you could end up waiting a long time for all of your results to be displayed, which doesn’t make sense if you only care about the first few.

Using the SQL LIMIT command

The limiting functionality is built into Mode to prevent you from accidentally returning millions of rows without meaning to (we’ve all done it). However, if you’re ever using SQL outside of Mode, you can manually add a limit with a SQL command. The following syntax does the same thing as having the box checked with a value of 100:

SELECT *
  FROM tutorial.us_housing_units
 LIMIT 100
Write a query that uses the LIMIT command to restrict the result set to only 15 rows.
Try it out See the answer

Congrats on learning the basics!

If you’re enjoying this SQL tutorial so far, we’d appreciate it if you’d
spread the love on Twitter.

Next Tutorial SQL WHERE

Looks like you've got a thing for cutting-edge data news.

So do we. Stay in the know with our regular selection of the best analytics and data science pieces, plus occasional news from Mode. Sign up here and we'll keep you posted:

Thanks! Keep an eye on your inbox for the next newsletter!

Contact

Request a Demo

hi@modeanalytics.com

415-689-7436

208 Utah Street, Suite 400
San Francisco CA 94103

Product

Compare plans

Mode Business

SQL editor

Notebooks

Reports

Dashboards

Embedded analytics

Mode for Slack

Customers

Integrations

Security

Resources

Help & support

Getting started webinar

Forum

Learn SQL

Learn Python

Data jobs

Data news

Drag and drop webinar

Scaling analytics webinar

Retention analytics ebook

Salesforce CRM ebook

Company

About

Careers

Blog

© Mode Analytics, Inc. 2018 Terms of Service Privacy Policy