Given for example a currency rates table with these columns (used 3 here, but in my situation there are about 30):
date | eur | usd | gbp
2010-01-28 | X | Y | Z
How do I convert it to this one (using row with the latest date):
currency | rate
eur | X
usd | Y
gbp | Z
I've come up with a query like this:
SELECT 'eur' AS currency, eur AS rate FROM rates WHERE date = (SELECT MAX(date) FROM rates)
UNION
SELECT 'usd' AS currency, usd AS rate FROM rates WHERE date = (SELECT MAX(date) FROM rates)
UNION
...
It's huge and ugly. Are there other solutions ?