Re: Syntax error needs explanation

From: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Syntax error needs explanation
Date: 2025-07-14 19:59:02
Message-ID: 6684eaa7-e6e2-a45b-cff9-44597ca3c8ad@appl-ecosys.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2025-07-14 20:00:54 Re: Performance of JSON type in postgres
Previous Message David G. Johnston 2025-07-14 19:56:16 Re: Syntax error needs explanation