As you can see, I have multiple databases(db10, db12) and each database contains individual customer data.
I want to query time series data for the currency stored in currency table.
The query is
Select Rupee, Yen from db10.currency where dateTime between value1 and value2;
Result
It is working fine against one database
but I want to process multiple queries against different dbs.
eg.
Select Rupee, Yen from db10.currency where dateTime between value1 and value2;
Select Dollar, Pound from db12.currency where dateTime between value1 and value2;
and so on.
Keep note that I generate these queries dynamically. All different information eg customerId, value1, value2, will be passed as a payload from Front
to Backend
. I consume the payload and make these queries dynamically.
I initial though it would work using UNION ALL as below
Select Rupee, Yen from db10.currency where dateTime between value1 and value2
UNION ALL
Select Dollar, Pound from db12.currency where dateTime between value1 and value2;
but lately I found it requires same column name, in same order to work. Unfortunately I have different columns eg. Rupee, Yen, Dollar, Pound so it doesn't work.
I want to know best and performant approach to deal with this type of query.
Expected Result something like below (or better if you can suggest something else)