Did you know ... Search Documentation:
SWI-Prolog owl logoINNER JOIN with an aggregation sub-query where the sub-query is constrained by a shared variable from the main query