12.8 LIMIT Options
Often we do not wish to see all of the rows from a table in our query result. One way to reduce the number of rows in a query result is to use the LIMIT clause in data.world. Note that LIMIT is not a standard SQL clause, and there are analogous ways to reduce the number of rows in a query result for other DBMS.
The LIMIT clause of a data.world query is included at the end of the SQL statement. The LIMIT clause starts with the keyword LIMIT and specifies a number of rows to include in the query result. For example, if we wish to see only five rows from the member table, we would add a LIMIT clause to the SQL statement, as shown below. The results of this query are found in Figure 12.17. Notice that only the first five rows of the query result are displayed.
SELECT first_name, last_name FROM Member LIMIT 5
One important way we can use the LIMIT clause is to see only the top (or bottom) rows of a table according to the values on a specific field. To accomplish this, we will first appropriately sort the query result by the values on that field and then apply the LIMIT clause to only view the required number of rows.
For example, we may wish to see the four biggest expenses incurred by the club. The syntax for this SQL statement is below. Notice that we first sort the rows on the Expense table by cost in descending order. This will arrange the highest cost item first in the query result. Each subsequent row of the query will include an item with a lower cost than the previous row. Therefore, by limiting the results to four rows, we will only see the four most costly expense items for the club (see Figure 12.18).
SELECT * FROM Expense ORDER BY cost DESC LIMIT 4
More information and examples about the data.world LIMIT clause can be found here: Basic Concepts: LIMIT