SQL WHERE.. IN 子句多列 [英] SQL WHERE.. IN clause multiple columns
本文介绍了SQL WHERE.. IN 子句多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在 SQL Server 中实现以下查询:
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 CRM_VCM_CURRENT_LEAD_STATUS
Where Lead_Key = :_Lead_Key
)
但是 WHERE..IN 子句只允许 1 列.如何将 2 列或更多列与另一个内部 SELECT 进行比较?
But the WHERE..IN clause allows only 1 column. How can I compare 2 or more columns with another inner SELECT?
推荐答案
你可以从子查询中创建一个派生表,并将 table1 连接到这个派生表:
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
这篇关于SQL WHERE.. IN 子句多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文