如果a表中的A字段和b表中得B字段同时在c表中存在,则显示A字段和B字段。这个语句怎么写啊

如题所述

如果c表是A,B两个字段的话
select a.A,b.B from a,b,c where a.A=c.A and b.B=c.B
如果c表只有一个C字段的话
select a.A,b.B from a,b,c c1,c c2 where a.A=c1.A and b.B=c2.B
或者
select a.A,b.B from a,b where exists (select * from c where a.A=c.C) and exists (select * from c where b.B=c.C)
或者
select * from (select a.A from a,c where a.A=c.C) aa ,(select b.B from b,c where b.B=c.C) bb
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-01-19
可以直接返回c表中的字段,这样快。
select c.A, c.B
from c
where exist
(select * from a,b,c
where a.A=c.A and b.B=c.B)
相似回答
大家正在搜