Aaron Rotem Aaron Rotem - 5 months ago 8
PHP Question

Query same fields from different tables

I have a bunch of different tables in a mySql database that all have the same structure. Essentially every user gets its own table, which is set up identically to the other tables. Is there a way to query all of these tables at once in php? It is like I am trying to take 5 small tables and make one master table to display on a webpage.

Answer

you can use union all

select col1, col2, ... coln
from your_table1
union all 
select col1, col2, ... coln
from your_table2
union all 
select col1, col2, ... coln
from your_table3
union all 
.....
select col1, col2, ... coln
from your_tableN