I have got two tables. Table1 stores the position order of the codes. Table2 stores information of each code. I'm trying to do a query which done a id, returns the order of each code and its associated information.
TABLE1
+-------+-----------+----------+-----------+-----------+-----------+
| id | position1 | positon2 | position3 | position4 | position5 |
+-------+-----------+----------+-----------+-----------+-----------+
| id1 | AA | CC | BB | EE | DD |
|-------|-----------|----------|-----------|-----------|-----------|
| id2 | BB | AA | DD | EE | CC |
+-------+-----------+----------+-----------+-----------+-----------+
TABLE2
+------+------------+--------------------+
| code | name | active_icon |
+------+------------+--------------------+
| AA | nameA | iconA |
| BB | nameB | iconB |
| CC | nameC | iconC |
| DD | nameD | iconD |
| EE | nameE | iconE |
+------+------------+--------------------+
Done an id (for example id = id2), the result I'm expecting is:
+----------------+------+------------+--------------------+
| position | code | name | active_icon |
+----------------+------+------------+--------------------+
| 1 | BB | nameB | iconB |
| 2 | AA | nameA | iconA |
| 3 | DD | nameD | iconD |
| 4 | EE | nameE | iconE |
| 5 | CC | nameC | iconC |
+----------------+------+------------+--------------------+
Any ideas? I think there must be an INNER JOIN but I don't know how to structure it.