SQL Server JOIN missing NULL values

前端 未结 8 1506
感情败类
感情败类 2020-12-04 15:15

Suppose I had the following 2 tables:

      Table1:                                Table2:
Col1:      Col2:     Col3:             Col1:       Col2:       Col         


        
8条回答
  •  心在旅途
    2020-12-04 15:41

    Use Left Outer Join instead of Inner Join to include rows with NULLS.

    SELECT Table1.Col1, Table1.Col2, Table1.Col3, Table2.Col4
    FROM Table1 LEFT OUTER JOIN 
        Table2 ON Table1.Col1 = Table2.Col1 
        AND Table1.Col2 = Table2.Col2
    

    For more information, see here: http://technet.microsoft.com/en-us/library/ms190409(v=sql.105).aspx

提交回复
热议问题