Reputation: 1643
I know I can combine tables with sql queries, but that's not what I am looking for.
Imagine having 10 tables, all are identical, but for certain reasons, I do not want to mix this data together in 1 table. Though! On the other hand, to create certain search results i want to be able to do a single sql query: (select * from combined_table where name='whatever')
In which I get data on the fly from all those 10 tables...
possible, yes/no?
Upvotes: 1
Views: 71
Reputation: 838176
You almost certainly want to put this data into a single table.
Let's say you have ten different types of data. Add a column called type
(you should choose a better name) and allow it to have a value from 1 to 10. Now your query will work without changes.
You can still get the data separately if you wish:
SELECT * from yourtable
WHERE name = 'whatever'
AND `type` = 3
The only reason I can think of for not doing it is if you have different users with different permissions and you want to use tables to control which users can see which data.
If despite the benefits, you still don't want to put the data in one table you can solve your issue by using UNION ALL
.
CREATE VIEW yourview AS
SELECT col1, col2, ..., coln FROM table1
UNION ALL
SELECT col1, col2, ..., coln FROM table2
UNION ALL
SELECT col1, col2, ..., coln FROM table3
UNION ALL
etc...
Upvotes: 2