TSQL, join to multiple fields of which one could be NULL

前端 未结 1 560
南笙
南笙 2021-01-24 17:04

I have a simple query:

SELECT * FROM Products p 
LEFT JOIN SomeTable st ON st.SomeId = p.SomeId AND st.SomeOtherId = p.SomeOtherId

So far so go

相关标签:
1条回答
  • 2021-01-24 17:41

    From Undocumented Query Plans: Equality Comparisons.

    SELECT *
    FROM   Products p
           LEFT JOIN SomeTable st
             ON st.SomeOtherId = p.SomeOtherId
                AND EXISTS (SELECT st.SomeId INTERSECT SELECT p.SomeId) 
    
    0 讨论(0)
提交回复
热议问题