首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-01-30 
求SQL语句:联合查询type表id,typename,englishname1,新闻,news2,法规,law3,服务,serviceflashAd表,id,jsNa

求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

热点排行
Bad Request.