Re: Left join syntax error

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: Left join syntax error
Дата
Msg-id 2e4c19a5-9547-40cc-93e3-75776547b26f@aklaver.com
обсуждение исходный текст
Ответ на Re: Left join syntax error  (Rich Shepard <rshepard@appl-ecosys.com>)
Ответы Re: Left join syntax error
Список pgsql-general
On 5/18/24 08: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.

The query needs to be:

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;

Only reference companies as c once.

> 
> Thanks,
> 
> Rich
> 
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com




В списке pgsql-general по дате отправления:

Предыдущее
От: Rich Shepard
Дата:
Сообщение: Re: Left join syntax error
Следующее
От: Rich Shepard
Дата:
Сообщение: Re: Left join syntax error