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

求SQL语句:联合查询
type表
id,typename,englishname
1,新闻,news
2,法规,law
3,服务,service

flashAd表,

id,jsName,
1,news_ad.js
2,law_ad.js

type表的englishName与flashad表的jsName   相对应。

要求:查询出来type表中,在flashad表中没有对应记录的记录。




------解决方案--------------------
select *
from [type]
where englishname not in (select jsName from flashAd)
------解决方案--------------------
select *
from [type] a
where not exists(
select *
from flashAd b
where a.englishname = b.jsName
)

or:

select *
from [type]
where englishname not in (select jsName from flashAd)

or:

select *
from [type]
where englishname <> any (select jsName from flashAd)
------解决方案--------------------
SELECT * FROM type
WHERE EXISTS (SELECT *FROM flashAd WHERE flashAd.jsName=type.englishname)

------解决方案--------------------
SELECT * FROM type
WHERE NOT EXISTS (SELECT *FROM flashAd WHERE flashAd.jsName=type.englishname)
------解决方案--------------------
select t.* from type表 t inner join flashAd表 f on t.jsName <> f.jsName