Re: Left join syntax error

From: Ray O'Donnell <ray(at)rodonnell(dot)ie>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Left join syntax error
Date: 2024-05-18 15:04:44
Message-ID: 7c4b1acc-951b-473f-bdc3-c4ae7298f875@rodonnell.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 18/05/2024 16:01, Rich Shepard wrote:
> On Sat, 18 May 2024, Ray O'Donnell wrote:
>
>> You need to include the alias for the table also - see "...from
>> companies as c..." in Shammat's example.
>
> Ray,
>
> That didn't work:
> bustrac-# FROM people as p, companies as c
> bustrac-# LEFT JOIN companies as c ON c.company_nbr = p.company_nbr;
> ERROR:  table name "c" specified more than once
>
> so I tried only the alias on the join line:
> bustrac-# LEFT JOIN c ON c.company_nbr = p.company_nbr;
> ERROR:  relation "c" does not exist
> LINE 3: LEFT JOIN c ON c.company_nbr = p.company_nbr;
>                   ^
> and that didn't work either.

Hi Rich,

Look again at Shammat's example! -

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

NB - "... from people as p left join companies as c on ...." - i.e. the
companies table (or its alias c) is only specified once.

HTH,

Ray.

>
> Thanks,
>
> Rich
>
>

--
Raymond O'Donnell // Galway // Ireland
ray(at)rodonnell(dot)ie

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2024-05-18 15:12:00 Re: Left join syntax error
Previous Message Rich Shepard 2024-05-18 15:04:13 Re: Left join syntax error