SQL WHERE.. IN clause multiple columns

前端 未结 13 1277
死守一世寂寞
死守一世寂寞 2020-11-29 15:56

I need to implement the following query in SQL Server:

select *
from table1
WHERE  (CM_PLAN_ID,Individual_ID)
IN
(
 Select CM_PLAN_ID, Individual_ID
 From CR         


        
13条回答
  •  一整个雨季
    2020-11-29 16:14

    You can make a derived table from the subquery, and join table1 to this derived table:

    select * from table1 LEFT JOIN 
    (
       Select CM_PLAN_ID, Individual_ID
       From CRM_VCM_CURRENT_LEAD_STATUS
       Where Lead_Key = :_Lead_Key
    ) table2
    ON 
       table1.CM_PLAN_ID=table2.CM_PLAN_ID
       AND table1.Individual=table2.Individual
    WHERE table2.CM_PLAN_ID IS NOT NULL
    

提交回复
热议问题