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 1ubPKN-000Qud-Pv for pgsql-general@arkaria.postgresql.org; Mon, 14 Jul 2025 19:59:07 +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 1ubPKL-00D3Ri-TD for pgsql-general@arkaria.postgresql.org; Mon, 14 Jul 2025 19:59:06 +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 1ubPKL-00D3Ra-Ik for pgsql-general@lists.postgresql.org; Mon, 14 Jul 2025 19:59:06 +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.96) (envelope-from ) id 1ubPKK-007iNF-0B for pgsql-general@postgresql.org; Mon, 14 Jul 2025 19:59:05 +0000 Received: from salmo.appl-ecosys.com (salmo.appl-ecosys.com [192.168.55.1]) by mail.appl-ecosys.com (Postfix) with ESMTP id 31D8C2A14D6 for ; Mon, 14 Jul 2025 12:59:02 -0700 (PDT) Date: Mon, 14 Jul 2025 12:59:02 -0700 (PDT) From: Rich Shepard To: pgsql-general Subject: Re: Syntax error needs explanation In-Reply-To: Message-ID: <6684eaa7-e6e2-a45b-cff9-44597ca3c8ad@appl-ecosys.com> References: <9c84776d-d938-9fa4-ab1-6ee960ce6e7d@appl-ecosys.com> <7ec33517-6dc1-4e1d-b741-0c26eba7cc79@aklaver.com> 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 Mon, 14 Jul 2025, Adrian Klaver wrote: > That does not matter, that is more for user convenience in figuring out what > the files are for. Adrian, Okay. I still have issues with the script. I want a count of companies with regulatory enforcement actions by industry. Since not all regulated companies have had such actions I want only those with rows in the enforcemewnt table and haven't before used the EXISTS operator and a subquery. The current version of the script: select c.company_nbr, c.company_name, c.industry from companies as c where exists ( select e.company_nbr from enforcement as e ) group by c.industry order by c.industry; And psql tells me that c.company_nbr must be in the group by clause. However, when I do that the output is a list of company numbers and names in each industry. My web searches on using the exists operator haven't provided the knowlege for me to use it properly. Rich