Mysql union from multiple database tables

mysql, php, union

Solution

try this:

(SELECT *, 'db1' as DB_NAME from db1..table1)
union
(SELECT *, 'db2' as DB_NAME from db2..table1)
union
(SELECT *, 'db3' as DB_NAME from db3..table1)
...

Problem

I have a group of databases which have a table with same schema. So, i am doing a `UNION` on this table to show the records from all databases, which works nice. But, now i have to detect which row belongs to which database/table, as i need to modify that particular record. I found this link on getting the `UNION`, but am unable to find the logic which determines row<->table relationship.

Original source

Related problems