I have multiple tables with identical columns and different data in them and i'm trying to make a single query to pull the data from all those tables and treat them as a single query. I also need to know from which table is the specific result. I found this to help me get a query from multiple tables, but when i try
$tables=array("loads", "loads_completed");
foreach ($tables as $table) {
$table = '`'.mb_ereg_replace('`','``',$table).'`';
$sql[] = "(
SELECT *
FROM $table
ORDER BY status
LIMIT 50
)";
}
$sql = implode(' UNION ALL ', $sql);
i get Query was empty
even though there is content in both tables.
This is what i found for displaying the result table, but i'm not sure how to form the query with array of tables.