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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -