tags:

views:

30

answers:

1

Im using php to do this:

while ($row = mysql_fetch_object($db_list)) {
 echo $row->Database . "<br>";

}

DB1 DB2 DB3 DB4

I want to add to this by adding a simple select query and running that against each database. the select will pull out the firstname of every user in the users table from each DB.

A: 

Try following

(SELECT username, 'DB1' AS Database FROM DB1.users)
UNION ALL
(SELECT username, 'DB2' AS Database FROM DB2.users)
UNION ALL
...etc

Changed UNIONs to UNION ALL

Cem Kalyoncu
Don't use UNION, use UNION ALL
nos
you are definitely right and I have updated the answer
Cem Kalyoncu