Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s8JYI-00BhY8-DC for pgsql-general@arkaria.postgresql.org; Sat, 18 May 2024 12:52:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s8JYG-005jCh-JT for pgsql-general@arkaria.postgresql.org; Sat, 18 May 2024 12:52:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s8JYG-005jCZ-8a for pgsql-general@lists.postgresql.org; Sat, 18 May 2024 12:52:40 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s8JYC-000sO5-JH for pgsql-general@lists.postgresql.org; Sat, 18 May 2024 12:52:39 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id C00112A43CF for ; Sat, 18 May 2024 05:52:34 -0700 (PDT) Date: Sat, 18 May 2024 05:52:34 -0700 (PDT) From: Rich Shepard Reply-To: Rich Shepard To: pgsql-general@lists.postgresql.org Subject: Left join syntax error Message-ID: <2c877258-61cc-dd2d-fac7-4f2a5c6293e7@appl-ecosys.com> MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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. Please show me what I've done incorrectly. TIA, Rich