I've got 4-5 tables that have near identical names and I need to select columns which have the same names from them. So far I'm doing this:
SELECT colA, colB FROM Table1
UNION
SELECT colA, colB FROM Table2
UNION
etc...
It seems like it could be overly verbose if you had more than a handful of similar tables and was wondering if there's any alternative syntax. Ideally I'd like something wildcard-y, like
SELECT colA, colB FROM Table%
If there is no alternative to UNION
, why not? Is there a specific reason for not allowing this? I would imagine it's because SQL should be as specific as possible when it comes to the table definitions (table + col names, types, etc) while allowing flexibility in data manipulation (hence we have wildcards for the rows).
There's no alternative I could think of. If I were nitpicky, I'd say that if you have similar tables that contain similar data, you should reconsider your database design :-)