I have multiple databases with the same architecture, same table and column names. With exception, one column name differs among the databases even though the values are the same. I need to write a universal MySQL query which can be applied to all the databases. I need to overcome that one problem where the column name may differ among the databases.
I have tried to lookup the problem in Google and the previous stackoverflow topics, none of them answered to my problem. I tried to solve the problem with 'case when ... then... else' and 'if exists...' statements - doesn't work or I am doing something wrong.
select(case when (select count(*) > 0
from information_schema.COLUMNS
where table_name = 'myTable'
and column_name = 'EUR')
then EUR
else USD
end)
from myTable
I expect to have a working query which checks if the 'EUR' column exists, if it does then select it, and, if it doesn't, then select 'USD' instead.