Search code examples
google-bigqueryspring-cloud-gcp-bigquery

Getting random rows in Big Query with different limit?


I have the following queries :

  • SELECT * FROM `datafusiontest-2897325.mergedquery.test_table LIMIT 10
  • SELECT * FROM `datafusiontest-2897325.mergedquery.test_table LIMIT 100
  • SELECT * FROM `datafusiontest-2897325.mergedquery.test_table LIMIT 10000

I am getting a different top result for each query.


Solution

  • As your query is not specifying an order, it is normal for results to be different each time - they are returning random rows from your table which meet the qualifying criteria.

    To get the same top n returned you should add an ORDER BY clause, for example:

    SELECT * 
    FROM `datafusiontest-2897325.mergedquery.test_table`
    ORDER BY date
    LIMIT 10