读书人

求SQL语句:联合查询,该如何处理

发布时间: 2012-01-30 21:15:58 作者: rapoo

求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

读书人网 >SQL Server

热点推荐