parent table (p) has 569,275 records and child table (c) has 633,283
All parents have at least 1 child
Why does inner join return more rows than the total rows on the child. I expect the same as on the child (633,283) but instead it returned 172 rows more (633,455).
Any explanation why?
Other counts. Note, there is one child record not in the parent (orphan) but I don't think that would explain the additional 172 rows.
Thoughts?
Jim
Code:
select count(*) from parent -- 569,275
select count(*) from child -- 633,283
All parents have at least 1 child
Code:
select p.* FROM [parent] p where p.pID in (select cid from child) -- 569,275 matches parent count
Why does inner join return more rows than the total rows on the child. I expect the same as on the child (633,283) but instead it returned 172 rows more (633,455).
Any explanation why?
Code:
select p.*, c.* FROM [parent] p
inner join child c on p.pid = c.cid -- 633,455
Other counts. Note, there is one child record not in the parent (orphan) but I don't think that would explain the additional 172 rows.
Code:
-- in child but not parrent
select cg.* FROM chargep cg where cg.CGCASEID not in (select cmcaseid from [CASEMASP]) -- 1
-- in parent but not in child
select p.* FROM [parent] p where p.pID not in (select cid from child) -- 0
-- in parent and at least one matching child. This matches parent count
select p.* FROM [parent] p where p.pID in (select cid from child) -- 569,275
Thoughts?
Jim