Select TOP 1000 across multiple tables

QuestionsSelect TOP 1000 across multiple tables
sethbeckerman5 Staff asked 4 years ago

I have a database where I create a new table every day and fill it with data (I know this isn't ideal, but I can't change this). Each table is of the form "TESTdata_xxxxx_DB", where xxxxx is incremented by 1 every day.
I need a simple way to select the top 1000 rows (where a specific condition is met) across many of those tables (i.e. across many dates). For example, I need to query across tables TESTdata_45800_DB, TESTdata_45801, …, TESTdata_45850_DB.
I have tried the following query, but clearly adding "to" doesn't work, and separating them by comma doesn't combine them the way I want:

Any help would be appreciated.


View on Stack Overflow