How to replace a complex SQL MINUS query with LEFT OUTER JOIN equivalent

后端 未结 3 2001
轮回少年
轮回少年 2021-01-18 11:53

Trying to figure how how to replace the following, with equivalent left outer join:

select distinct(a.some_value)
from table_a a, table_b b
where a.id = b.a_         


        
3条回答
  •  别那么骄傲
    2021-01-18 12:22

    SELECT * FROM
    (
      select distinct(a.some_value)
      from table_a a, table_b b
      where a.id = b.a_id 
      and b.some_id = 123
      and b.create_date < '2014-01-01' 
      and b.create_date >= '2013-12-01'  
    ) x
    LEFT JOIN 
    (
      select distinct(a.some_value)
      from table_a a, table_b b
      where a.id = b.a_id 
      and b.some_id = 123 
      and b.create_date < '2013-12-01'
    ) y
    ON 
      x.some_value = y.some_value
    WHERE 
      y.some_value IS NULL
    

提交回复
热议问题