Assuming I have the following two tables:
**Table A**
ID Day Month Year
------------------------
1 1 1 1900
3 13 3 2009
49 28 2 1984
**Table B**
ID ABC_1_1_1900 ABC_2_1_1900 ... ABC_31_12_2100
-------------------------------- ... ---------------
1 431 15449 98565
2
3 ....
.
.
n ....
and would like to get the following table:
**Table C**
ID ABC
------------------------
1 431
3 (value B.ABC_13_3_2009 for ID=3)
49 (value B.ABC_28_2_1984 for ID=49)
What essentially I'm trying to achieve is, get a subset of Table B by matching the row contents of A to the column names of B and inner joining on the IDs.
The equivalent would be
SELECT A.ID, B.CONCAT('ABC_', A.Day, '_', A.Month, '_', A.Year) AS ABC
FROM A
INNER JOIN B ON A.ID=B.ID
which unfortunately doesn't work. Any ideas greatly appreciated!