Join in Sqlite Intermediary table -
i have schema in sqlite database
create table `cars` ( `id` integer, `name` text, primary key(id) ); create table `owners` ( `id` integer, `name` text, primary key(id) );
and intermediary table between owners table , cars table
create table `ownercars` ( `ownerid` integer, `carid` integer, primary key(ownerid,carid), foreign key(`ownerid`) references `owners`(`id`), foreign key(`carid`) references `cars`(`id`) );
querying i'll owners have cars , car count
select ownerid, count(carid) carscount ownercars inner join owners on ownerid = id group by(ownerid)
how can owners (including without cars , car count 0). help!
use left outer join query, keep owner table left.
select o.id, count(carid) carscount owner o left outer join ownercars on ownerid = o.id group by(o.id)
Comments
Post a Comment