Re: Left join syntax error

From: Shammat <shammat(at)gmx(dot)net>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Left join syntax error
Date: 2024-05-18 13:19:41
Message-ID: 9d899286-3a73-4894-a6e0-eab529c92e65@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Am 18.05.24 um 14:52 schrieb Rich Shepard:
> It's been a _very_ long time since I wrote a SQL script and, despite looking
> at my SQL books and web pages, I don't know how to fix the error.
>
> The three line script is:
> -----
> SELECT p.lname, p.fname, p.job_title, p.company_nbr, p.email, c.company_name
>   FROM people as p, companies as c
> LEFT JOIN companies ON c.company_nbr = p.company_nbr;
> -----
>
> and psql responds:
> ERROR:  invalid reference to FROM-clause entry for table "p"
> LINE 3: LEFT JOIN companies ON c.company_nbr = p.company_nbr;
>                                                ^
> HINT:  There is an entry for table "p", but it cannot be referenced from this part of the query.

Don't put the second table in the FROM part

SELECT p.lname, p.fname, p.job_title, p.company_nbr, p.email, c.company_name
FROM people as p
LEFT JOIN companies as c ON c.company_nbr = p.company_nbr

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Troels Arvin 2024-05-18 14:19:11 Re: utf8 vs UTF-8
Previous Message Rich Shepard 2024-05-18 12:52:34 Left join syntax error