Re: Left join syntax error

2024-05-18 Thread Rich Shepard
On Sat, 18 May 2024, Adrian Klaver wrote: Show the complete query. Take the error message as correct, you are specifying 'companies as c' more then once. Adrian, I saw that but didn't know how to specify the alias only one time. Thanks, Rich

Re: Left join syntax error

2024-05-18 Thread Rich Shepard
On Sat, 18 May 2024, Ray O'Donnell wrote: 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 " -

Re: Left join syntax error

2024-05-18 Thread Rich Shepard
On Sat, 18 May 2024, Adrian Klaver wrote: 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, Adrian. I mis-read your origi

Re: Left join syntax error

2024-05-18 Thread Erik Wienhold
On 2024-05-18 17:12 +0200, David G. Johnston wrote: > Too lazy to find the docs right now but what you are observing is basically > an operator precedence effect. The comma join hasn’t happened at the time > the left join is evaluated and so other tables in the comma join cannot > appear in the on

Re: Left join syntax error

2024-05-18 Thread David G. Johnston
On Sat, May 18, 2024 at 7:49 AM Adrian Klaver wrote: > On 5/18/24 07:46, Rich Shepard wrote: > > On Sat, 18 May 2024, Shammat wrote: > > > >> 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

Re: Left join syntax error

2024-05-18 Thread Rich Shepard
On Sat, 18 May 2024, Erik Wienhold wrote: Yes, Rich probably just wants the left join. Eric, You're correct: I want certain colums from the people table with their company name from the companies table. But I wonder if the implicit cross join syntax ("FROM peoples, companies") should actual

Re: Left join syntax error

2024-05-18 Thread Tom Lane
Erik Wienhold writes: > But I wonder if the implicit cross join syntax ("FROM peoples, companies") > should actually produce this error because the explicit cross join > works: > SELECT p.lname, p.fname, p.job_title, p.company_nbr, p.email, > c.company_name > FROM people as p > C

Re: Left join syntax error

2024-05-18 Thread Erik Wienhold
I wrote: > But I wonder if the implicit cross join syntax ("FROM peoples, companies") > should actually produce this error because the explicit cross join > works: > > SELECT p.lname, p.fname, p.job_title, p.company_nbr, p.email, > c.company_name > FROM people as p > CROSS JOIN co

Re: Left join syntax error

2024-05-18 Thread David G. Johnston
On Saturday, May 18, 2024, Erik Wienhold wrote: > On 2024-05-18 15:19 +0200, Shammat wrote: > > 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. >

Re: Left join syntax error

2024-05-18 Thread Adrian Klaver
On 5/18/24 08:04, Rich Shepard wrote: On Sat, 18 May 2024, Adrian Klaver wrote: ... LEFT JOIN companies as c ON c.company_nbr = p.company_nbr; Adrian, Tried that: bustrac-# LEFT JOIN companies as c ON c.company_nbr = p.company_nbr; ERROR:  table name "c" specified more than once Show the c

Re: Left join syntax error

2024-05-18 Thread Ray O'Donnell
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

Re: Left join syntax error

2024-05-18 Thread Rich Shepard
On Sat, 18 May 2024, Adrian Klaver wrote: ... LEFT JOIN companies as c ON c.company_nbr = p.company_nbr; Adrian, Tried that: bustrac-# LEFT JOIN companies as c ON c.company_nbr = p.company_nbr; ERROR: table name "c" specified more than once Thanks, Rich

Re: Left join syntax error

2024-05-18 Thread Adrian Klaver
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.c

Re: Left join syntax error

2024-05-18 Thread Rich Shepard
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: tab

Re: Left join syntax error

2024-05-18 Thread Erik Wienhold
On 2024-05-18 15:19 +0200, Shammat wrote: > 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.lna

Re: Left join syntax error

2024-05-18 Thread Adrian Klaver
On 5/18/24 07:46, Rich Shepard wrote: On Sat, 18 May 2024, Shammat wrote: 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 Shammat, I tried t

Re: Left join syntax error

2024-05-18 Thread Ray O'Donnell
On 18/05/2024 15:46, Rich Shepard wrote: On Sat, 18 May 2024, Shammat wrote: 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 Shammat, I trie

Re: Left join syntax error

2024-05-18 Thread Rich Shepard
On Sat, 18 May 2024, Shammat wrote: 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 Shammat, I tried this with this result: ERROR: missing FR

Re: Left join syntax error

2024-05-18 Thread Shammat
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

Left join syntax error

2024-05-18 Thread 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