SQL: Statement Fundamentals

LIMIT

LIMIT allows you to limit the number of rows you get back after a query

Syntax:

-- Limit
SELECT column_1, column_2
FROM table_name
LIMIT number_of_rows;

Example: Select all rows and columns from the customer table and limit the number of rows to five.

-- Limit the number of rows to five
SELECT *
FROM customer
LIMIT 5;
##   customer_id store_id first_name last_name                               email address_id activebool create_date         last_update active
## 1         524        1      Jared       Ely        jared.ely@sakilacustomer.org        530       TRUE  2006-02-14 2013-05-26 14:49:45      1
## 2           1        1       Mary     Smith       mary.smith@sakilacustomer.org          5       TRUE  2006-02-14 2013-05-26 14:49:45      1
## 3           2        1   Patricia   Johnson patricia.johnson@sakilacustomer.org          6       TRUE  2006-02-14 2013-05-26 14:49:45      1
## 4           3        1      Linda  Williams   linda.williams@sakilacustomer.org          7       TRUE  2006-02-14 2013-05-26 14:49:45      1
## 5           4        2    Barbara     Jones    barbara.jones@sakilacustomer.org          8       TRUE  2006-02-14 2013-05-26 14:49:45      1