Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Inner Join and null values

Author  Topic 

kgundava
Yak Posting Veteran

66 Posts

Posted - 2011-08-04 : 08:07:50
Hi All,
As i am new to sql server, i was curious how does the inner join behave if it encounters a null value in the columns which are used for joining two tables.Is there any way to just ignore them.
Thanks,
Krishna

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-04 : 08:19:10
inner join wont take null values while joining. if you want to specifically include them use a condition like
...
(table1.col1 = table2.col2 or table2.col2 is null)
...

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

kgundava
Yak Posting Veteran

66 Posts

Posted - 2011-08-04 : 12:13:32
Hi Visakh,
Thanks for the reply...If i have a multiple conditions in a inner join such T.ColmA=S.COLmA and T.ColmB=S.COLmB ..... and if one of these columns(both tables) have null values then will it skipt the total row or will it just ignore the condition ?????
Thanks......
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-04 : 12:37:06
it will skip total row as inner join wont return any of rows with null values in any of column.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -