02-11-2022 01:37 AM
Hello All,
While trying to write an sql querry I ran into the following case that i can't explain and was wondering if someone could:
run sql select count(numplan.pkid) from numplan
(count)
=======
2721
run sql select count(numplan.pkid) from numplan inner join devicenumplanmap on devicenumplanmap.fknumplan = numplan.pkid
(count)
=======
6169
Inner join is supposed to be the overlap between two sets, which means that there should be no way for the result to be bigger than any of the two sets going in
any ideas?
02-11-2022 11:52 PM
Inner Join clause in SQL Server creates a new table (not physical) by combining rows that have matching values in two or more tables.
AFAIK, you are making a table showing the count of numplan which has devicenumplanmap.fknumplan = numplan.pkid
02-14-2022 12:07 AM
I figured it out, I made a fundamentally incorrect assumption, that devicenumplanmap.fknumplan has unique values, however it turns out that multiple entries in devicenumplanmap.fknumplan point to the same numplan.pkid. I can now fix this using select distinct
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide