日期:2014-05-18  浏览次数:20745 次

一个表中两个字段不在另一个表中的查询
表1
  A B C D
表2
  A x

表3

  A e f g x

查询表1和表2相等的A对应的x 不在表3中  
 

------解决方案--------------------
SQL code

select
from 表1 a
inner join 表2 b on a.A=b.A
left join 表3 c on b.x=c.x
where c.x is null

------解决方案--------------------
你是一a表为标准,还是ab表为标准?
------解决方案--------------------
select x from 表3 c where x not in
(select x from 表2 a left join 表1 b on a.a=b.a)