Answer Felipe uses Legacy SQL. Here is the solution in standard SQL.
If your table names have a predictable suffix, for example the GitHub example in your link (which uses the YYYYMMDD suffix for each day), you can use wildcard tables and TABLE_SUFFIX :
SELECT COUNT(*) FROM `githubarchive.day.events_*` WHERE _TABLE_SUFFIX = ( SELECT MAX(SUBSTR(table_id, -8)) FROM `githubarchive.day.__TABLES_SUMMARY__` WHERE REGEXP_CONTAINS(table_id, "events_\\d{8}") )
If you want to rely on BigQuery metadata about creation time instead of a prefix, you can do:
SELECT COUNT(*) FROM `githubarchive.day.*` WHERE _TABLE_SUFFIX = ( SELECT table_id FROM `githubarchive.day.__TABLES_SUMMARY__` ORDER BY creation_time DESC LIMIT 1 )
Please note that if your project has tables with different schemas, the last syntax is dangerous, since the query will use the schema of the first table that it sees in the template.
If you are trying to create tables separated by date, there is a BigQuery function called date tables that does just that and simplifies the query after that.
source share