BigQuery - Select Top N Records

visibility 11,641 access_time 2 years ago languageEnglish

In BigQuery, there is no TOP N clause implemented however there is LIMIT clause available.

LIMIT clause

The following query retrieves 10 records from table table_name of data set data_set in project project_test.

select * from  `project_test.data_set.table_name` limit 10;

Cost implications

warning LIMIT clause doesn't reduce cost! Please add necessary filters and only query the required columns to reduce cost.

It's very important to understand that LIMIT doesn't reduce your query cost. In the above example, all the records in the table will be read and then only 10 will be returned.  Thus please take this into consideration.

Preview feature

If the purpose is to inspect the sample data in the table, please use preview feature of BigQuery which is free.

Follow these steps to do that:

  • Expand your BigQuery project and data set.
  • Select the table you'd like to inspect.
  • In the opened tab, click Preview

Preview will show the sample data in the table.


info Last modified by Raymond 2 years ago copyright This page is subject to Site terms.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

timeline Stats
Page index 26.82
More from Kontext
BigQuery: Create Partitioned Table as SELECT
visibility 1,057
thumb_up 0
access_time 13 months ago
PySpark: Read File in Google Cloud Storage
visibility 4,942
thumb_up 0
access_time 2 years ago
PySpark: Read File in Google Cloud Storage
BigQuery - Insert-Only Virtualized SCD Type 2
visibility 998
thumb_up 2
access_time 9 months ago
BigQuery - Insert-Only Virtualized SCD Type 2