I have two tables: tableA and tableB. TableA has a field idA and tableB has a record idB and idBPtrA where idBptrA is a pointer to tableA (one of the idA).
I want, using postgres, to select records from a TableA that have the minimal number of records in tableB.
select idA,idB,count(idBPtrA) as c
group by idBPtrA
where idA=idB order by c
I think this is the query that you want:
select a.idA, count(b.idB) as c from tableA a left join tableB b on a.idA = b.idptrA group by a.idA order by c;
JOINsyntax. Simple rule: Never use commas in the