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.
Yeah, you need both to read up on aggregate queries and correlated subqueries which is typically how one makes uses of exists (it's called a semi-join in this formulation)