So, I have two tables, one of which is like this:
Table: data
id | col_1 | col_2 | col_3 | col_4 ------------------------------------------------------ 1 | 167 | 12 | 15 | something1 2 | 198 | 27 | 12 | something2 3 | 253 | 15 | 17 | something3
and Table: catalog
id | col_1 ----------------- 12 | red 15 | yellow 17 | pink 27 | green
Now, what I am trying to do is get col_1, col_2, col_3 and col_4 from the data table, but instead of getting the values of col_2 and col_3, these should be replaced by the col_1 of the catalog table, according to the catalog id.
For example, I want it to return, for every row of the data table, the following info:
167 | red | yellow | something1
198 | green | red | something2
253 | yellow | pink | something3
I tried this:
SELECT data.col_1, catalog.col_1, catalog.col_1, data.col_4
FROM data
INNER JOIN catalog ON data.col_2 = catalog.id
INNER JOIN catalog ON data.col_3 = catalog.id
but to no effect and surprise.
I simply can't find how to inner join multiple columns of one table to a single column of another, and Google has not been of great help. I actually don't know if I am searching with the right keywords.
catalogrequires its own alias.datahas an id not present incatalog?