SQL Server LEFT JOIN and WHERE clause

前端 未结 5 655
被撕碎了的回忆
被撕碎了的回忆 2020-12-30 03:53

Here is my code

SELECT ID, Name, Phone 
FROM Table1 
LEFT JOIN Table2 ON Table1.ID = Table2.ID
WHERE Table1.ID = 12 AND Table2.IsDefault = 1
<
5条回答
  •  隐瞒了意图╮
    2020-12-30 04:01

    Try this :

    SELECT ID, Name, Phone 
    FROM Table1 
    LEFT JOIN Table2 ON Table1.ID = Table2.ID
    WHERE Table1.ID = 12 AND isnull(Table2.IsDefault,1) = 1
    

    You were almost there :-)

提交回复
热议问题