cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
644
Views
10
Helpful
2
Replies

SQL inner join question

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

 

259673524_479077087111767_6600516223911615983_n.png

 

any ideas?

2 Replies 2

Nithin Eluvathingal
VIP Mentor VIP Mentor
VIP Mentor

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

 

 



Response Signature


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

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Recognize Your Peers