I've been searching for an answer to this for a while and am just not successful. Sorry if this is a duplicate.
I have two tables:
table1
------------------------
| id | name |
------------------------
| c1 | name1 |
| c2 | name2 |
| c3 | name3 |
| c4 | name4 |
------------------------
table2
------------------------------------------------
| id | c1 | c2 | c3 |
------------------------------------------------
| 1 | data11 | data21 | data31 |
| 2 | data12 | data22 | data32 |
------------------------------------------------
I need data from the second table, renaming the columns with the contents of the first table like this. The number of columns might not match.
result
------------------------------------
| id | name1 | name3 |
------------------------------------
| 1 | data11 | data31 |
| 2 | data12 | data32 |
------------------------------------
[Edit] I am selecting data from the second table like this: "SELECT c1,c3 FROM table2 WHERE id ..." so I don't "know" the names when I do the select.
First I was thinking it would be a simple JOIN, but obviously it's not. I'm kind of stuck right now wondering how to approach this. Thanks