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 1swUCa-0044v1-0U for pgsql-sql@arkaria.postgresql.org; Thu, 03 Oct 2024 22:21:40 +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 1swUCZ-005FCO-9g for pgsql-sql@arkaria.postgresql.org; Thu, 03 Oct 2024 22:21:39 +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 1swUCZ-005FCF-0h for pgsql-sql@lists.postgresql.org; Thu, 03 Oct 2024 22:21:39 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1swUCV-002PlV-1i for pgsql-sql@lists.postgresql.org; Thu, 03 Oct 2024 22:21:38 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 493MLWJp472956; Thu, 3 Oct 2024 18:21:32 -0400 From: Tom Lane To: Sam Stearns cc: pgsql-sql@lists.postgresql.org, Peter Garza , Henry Ashu Subject: Re: invalid reference to FROM-clause entry for table In-reply-to: References: Comments: In-reply-to Sam Stearns message dated "Thu, 03 Oct 2024 15:14:46 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <472954.1727994092.1@sss.pgh.pa.us> Date: Thu, 03 Oct 2024 18:21:32 -0400 Message-ID: <472955.1727994092@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Sam Stearns writes: > This one is really doing my head in: > ... > FROM (pud_fme_data d > inner join csbuser u on (u.userid=d.user_id) > inner join office o on (u.officeid=o.officeid) > left outer join login l on (l.userid=u.userid) ) alias6; > ERROR: invalid reference to FROM-clause entry for table "o" > LINE 2: o.crmaccountid AS crm_account_id, > ^ > DETAIL: There is an entry for table "o", but it cannot be referenced from > this part of the query. IIRC, the join alias "alias6" hides any table aliases inside it. Leave that off. Or reference the column as "alias6.crmaccountid". (This way might require fooling around with column aliases so that crmaccountid is a unique column name within that scope.) regards, tom lane