Selecting the Top 5 Rows

One of the most useful use cases for selecting the Top 5 rows from a table is to get a sense of what the data is like within the table. While in Excel you can quickly see what the table looks like visually, in SQL we’re dealing with many tables and selecting the top 5 rows can easily and quickly give a sense of the type of data we’re dealing with.

SELECT TOP 5 *

FROM database_table

ORDER BY 2022 estimate DESC

  • You can also select the top 1, 5, 100, etc from a table.

  • Further, if you wouldn’t like all columns returned, you can specify which top 5 columns to return with:

    • (SELECT TOP 5 City, ST FROM database_table)

  • Note it’s important to include the ORDER BY since it specifies the ordering, otherwise the TOP 5 from New York to Phoenix may not necessarily have been the 5 rows returned.