select - SQL count on a joined table -
i've got 2 tables, 1 persons
, 1 relationships
.
i want retrieve person children.
currently i'm joining tables this:
select persons.id, persons.native_country, relationships.person_id, relationships.relation persons inner join relationships on relationships.person_id = id , relationships.relation = 'child';
now i'm trying count persons.id
, max, not sure how that.
you can try using group by:
select persons.id, count(*) "no of children" persons inner join relationships on relationships.person_id = id , relationships.relation = 'child' group persons.id;
Comments
Post a Comment