I've got three database tables that are connected trough each other but not directly. Here are the tables:
Table one
-----------
id
rank
table_two_id
Table two
-----------
id
amount
table_three_id
Table three
-----------
id
name
So each row in table one can be directly linked to the row in the third table. I need to get some columns from table_one plus the name column from the third column.
I've tried many combinations so far, but this one seems to be the most promising so far, however I can't get it to work :
select (select s.table_three_id
from table_two s
where s.id = r.table_two_id) as three_id,
table_three.name
from table_one r
INNER JOIN table_three ON (three_id = table_three.id);
I get an error saying column three_id doesn't exist. How do I get the info from the third table based on key from table_one trough table_two.
three_id...table_three