Search code examples
postgresqljoinforeign-data-wrapper

Join three foreign tables in postgreSQL


I have three foreign tables (visits, parts, problemdescription) having a common column named: "startDateTime"

I want to join them, so I used the following query:

select v."startDateTime", p.znumber, pd.remark FROM visits v
INNER JOIN  parts p
on s."startDateTime"=p."startDateTime" INNER JOIN problemdescription pd
on s."startDateTime"=pd."startDateTime";

But I get this error for postgres:

ERROR: missing FROM-clause entry for table "s"


Solution

  • Replace s with v, because you haven't table "s".

    select v."startDateTime", p.znumber, pd.remark FROM visits v
    INNER JOIN  parts p
    on v."startDateTime"=p."startDateTime" INNER JOIN problemdescription pd
    on v."startDateTime"=pd."startDateTime";