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 1s8Lc9-00BxaG-HL for pgsql-general@arkaria.postgresql.org; Sat, 18 May 2024 15:04:50 +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 1s8Lc9-007Jgq-HK for pgsql-general@arkaria.postgresql.org; Sat, 18 May 2024 15:04:49 +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 1s8Lc9-007Jgd-6s for pgsql-general@lists.postgresql.org; Sat, 18 May 2024 15:04:49 +0000 Received: from srv01.teladesign.ie ([2001:41c9:1:41d::10]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s8Lc6-000tOc-3x for pgsql-general@lists.postgresql.org; Sat, 18 May 2024 15:04:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rodonnell.ie; s=exim; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: From:References:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To:Cc: Content-ID:Content-Description:Resent-Message-ID; bh=nVAmQ7wcO9Gw+52UrBp+hFNjvjgZ7TrhxVoDC/FLyyw=; b=kfgiezXx0VKN6LWfARnTs6cazw sBgMcZAtAWkD9pLti2V84FCMlTIA79Rrm44sQi13txeCsRKFbMHt5mEpnjUM8qWe7x8YsSCrdHwUh 0hTjX0E+i1pVhGhgZM3NHc6bEPb7AurEimgEFqaxOggF4m7NWCwKb1VHIpBdlZXQpRK8=; Received: from [64.43.146.234] (helo=[192.168.1.162]) by srv01.teladesign.ie with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1s8Lc4-0005KT-Sw; Sat, 18 May 2024 16:04:45 +0100 Message-ID: <7c4b1acc-951b-473f-bdc3-c4ae7298f875@rodonnell.ie> Date: Sat, 18 May 2024 16:04:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Left join syntax error To: Rich Shepard , pgsql-general@lists.postgresql.org References: <2c877258-61cc-dd2d-fac7-4f2a5c6293e7@appl-ecosys.com> <9d899286-3a73-4894-a6e0-eab529c92e65@gmx.net> <3216489-758a-faef-b21b-84c9679f53c@appl-ecosys.com> <23486d5-be1e-f152-2b97-e027ef89a810@appl-ecosys.com> Content-Language: en-GB From: Ray O'Donnell In-Reply-To: <23486d5-be1e-f152-2b97-e027ef89a810@appl-ecosys.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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@rodonnell.ie