SQL WHERE.. IN clause multiple columns

前端 未结 13 1278
死守一世寂寞
死守一世寂寞 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:22

    Why use WHERE EXISTS or DERIVED TABLES when you can just do a normal inner join:

    SELECT t.*
    FROM table1 t
    INNER JOIN CRM_VCM_CURRENT_LEAD_STATUS s
        ON t.CM_PLAN_ID = s.CM_PLAN_ID
        AND t.Individual_ID = s.Individual_ID
    WHERE s.Lead_Key = :_Lead_Key
    

    If the pair of (CM_PLAN_ID, Individual_ID) isn't unique in the status table, you might need a SELECT DISTINCT t.* instead.

提交回复
热议问题