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 1s8LpV-00Byr0-JO for pgsql-general@arkaria.postgresql.org; Sat, 18 May 2024 15:18:38 +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 1s8LpV-007jkc-NH for pgsql-general@arkaria.postgresql.org; Sat, 18 May 2024 15:18:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s8LpV-007jkU-Cs for pgsql-general@lists.postgresql.org; Sat, 18 May 2024 15:18:37 +0000 Received: from mail.appl-ecosys.com ([50.126.108.78]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s8LpT-000po6-32 for pgsql-general@lists.postgresql.org; Sat, 18 May 2024 15:18:36 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id 0470A2A43CF for ; Sat, 18 May 2024 08:18:34 -0700 (PDT) Date: Sat, 18 May 2024 08:18:34 -0700 (PDT) From: Rich Shepard To: pgsql-general@lists.postgresql.org Subject: Re: Left join syntax error In-Reply-To: <7d422a60-c581-485d-b5fd-4b2bb284b919@ewie.name> Message-ID: <775a2a40-9353-9275-8d7e-1e4c1fccad21@appl-ecosys.com> References: <2c877258-61cc-dd2d-fac7-4f2a5c6293e7@appl-ecosys.com> <9d899286-3a73-4894-a6e0-eab529c92e65@gmx.net> <7d422a60-c581-485d-b5fd-4b2bb284b919@ewie.name> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 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 companies as c > LEFT JOIN companies ON c.company_nbr = p.company_nbr; Aha! I ignored the cross join because I don't need all columns from both tables. And it worked here (slowly) with a Ryzen7 2700 CPU and 64G RAM. > If you just move the LEFT JOIN condition to the WHERE clause it works as > well, which indicates that the aliases from the implicit cross join do > work as if it has been an explicit cross join: > > 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 true > WHERE c.company_nbr = p.company_nbr; This didn't work as well; too many repeats for each row in people. Thank you for a valuable lesson, Eric. Best regards, Rich