[英]Finding data from Table A and Table B relation
By see below tables how to (write query) get Table A
data and status = InActive
with no Data in Table B
通过查看下表,如何(写查询)获取Table A
数据,并且status = InActive
, Table B
没有数据
Example : 4 Comm4 InActive
示例: 4 Comm4 InActive
Table A
AID Name Status
-- --- --
1 comm1 Active
2 comm2 Active
3 Comm3 InActive
4 Comm4 InActive
5 Comm5 InActive
Table B
BID Name AID
--- ---- ---
11 James 1
12 Kris 2
13 Dan 3
14 Steve 3
15 Brian 5
It's quite simple 很简单
select * from tableA
where status = 'InActive'
and not exists (select * from tableB where tableA.AID = tableB.AID)
select tableA.*
from tableA
left join tableB
on tableA.AID = tableB.AID
and tableA.status = 'InActive'
where tableB.AID is null
The not exists from Szymon is correct and may be more efficient Szymon的不存在是正确的,可能会更有效
Here you try. 在这里尝试。
select *
from #table_one
where Status = 'InActive'
and not exists
(
select 1 from #table_two where AID = #table_one.AID
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.