
December 22nd, 2012, 10:23 AM
|
|
Registered User
|
|
Join Date: Aug 2011
Posts: 18
Time spent in forums: 2 h 36 m 55 sec
Reputation Power: 0
|
|
These are all good suggestions. But I was wondering whether there was a way to define the SELECT statement to look for tables with a certain pattern in their name, similar to the LIKE feature for columns.
Thanks.
Quote: | Originally Posted by requinix Not like that no.
The real problem is that you have a bunch of tables all for specific years. You really should be storing everything in one table, and including an extra column to indicate the year (if there isn't already something you can use).
You may be able to create VIEWs for each of the tables you're deprecating.
Code:
CREATE VIEW `table_2012` AS SELECT * FROM `table` WHERE `yearValue` = 2012;
If that doesn't work I'd even consider using triggers (per-year tables have INSERT/UPDATE triggers to copy the action in the main table, main table has basically the same but going into the per-year tables) just so that you can collect all the data in one master location.
But to answer the question you can do a UNION between all of them. (Still have to write the queries though.)
Code:
SELECT ...
UNION ALL
SELECT ...
UNION ALL
SELECT ...
With a "UNION" alone MySQL will try to remove duplicates for you. If you want them, or know that there won't be any, "UNION ALL" will instruct it not to do so. |
|