Using the info from this other StackOverFlow question I can query the list of all databases that have the same table:
SELECT
table_name, table_schema AS dbname
FROM
INFORMATION_SCHEMA.TABLES
WHERE
table_name = 'myCommonTableName'
This will give me the list of database that have the table I'm interested in. My question is now how can I view the values of those tables instead of just the names of the tables. In other words something along the lines of:
SELECT
myCommonTableName.id
FROM
[all tables from all databases - query above]
WHERE
myCommonTableName.someValue > someTest
In other words I want to get all the rows from all the identical tables (multi-tenant) for all the databases that match a specific criteria. I need to do this for user and account management. Is it possible? And if so how?
UPDATE To further clarify as there seems to be some confusion, I do NOT want to do this:
SELECT * FROM myTable WHERE myTable.id =
(SELECT id FROM anotherTable WHERE someOtherCondition)
.
What I'm trying to do is something like:
SELECT * FROM [databaseList].myTable WHERE myTable.id = 1
.
Or to be more precise:
for(listOfDatabases)
SELECT * FROM [database.x].myTable WHERE myTable.id = 1
Basically I want to get all the results from all myTable in all my databases where they have the same ID value of 1. It's actually a different WHERE clause but you get the idea.