34,594
社区成员
发帖
与我相关
我的任务
分享
select * from B where exists (select 1 from A where A.name='aaa' and A.id=B.pid)
--1.1 插入到临时表
select *
INTO #tmp
from A where name='aaa';
--1.2 创建临时表上的索引,提高后面查询的效率
CREATE UNIQUE CLUSTERED INDEX ix_tmp ON #tmp(id);
--2. 查询临时表
SELECT * FROM #tmp;
--3. 查询B与临时表
SELECT * FROM B INNER JOIN #tmp AS A ON B.pid=A.id;
--4. 删除临时表;
DROP TABLE #tmp;