Restricting a LEFT JOIN

后端 未结 5 641
梦如初夏
梦如初夏 2021-01-06 03:59

I have a table, let\'s call it \"a\" that is used in a left join in a view that involves a lot of tables. However, I only want to return rows of \"a\" if they also join wit

5条回答
  •  轮回少年
    2021-01-06 04:34

        Select ... 
        From Main 
         Left Join a on main.col2 = a.col2
        where a.col3 in (select b.col3 from b) or a.col3 is null
    

    you may also need to do some indexing on a.col3 and b.col3

提交回复
热议问题