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

连接查询的语句,该如何解决

2012-01-09 
连接查询的语句我有2个表查询表一的reportname,path内容要求,返回reportname不包含在表二reportname的列中

连接查询的语句
我有2个表
查询表一的   reportname,path内容
要求,返回   reportname   不包含在   表二   reportname的列中,表二的列为username=xxx,
我无论用 <> ,not   in都是取不到正确的结果
而,IN   ,   =   可以取到相反要求的正确结果。。怎么搞啊

SELECT   dbo.ReportList.*
FROM   dbo.ReportList   INNER   JOIN
            dbo.UserReport   ON   dbo.ReportList.ReportName   <>   dbo.UserReport.ReportName

[解决办法]
SELECT dbo.ReportList.*
FROM dbo.ReportList a,
dbo.UserReport b where a.ReportName <> b.ReportName

[解决办法]
select reportname,path from ReportList where reportname not in (select reportname from UserReport )
[解决办法]
SELECT dbo.ReportList.*
FROM dbo.ReportList a,
dbo.UserReport b where isnull(a.ReportName, ' ') <> isnull(b.ReportName, ' ')
[解决办法]
select * from ReportList a where not exists(select * from UserReport where ReportName=a.ReportName)
[解决办法]
--try

SELECT dbo.ReportList.*
FROM dbo.ReportList as A
where exists(select 1 from UserReport where ReportName <> A.ReportName)


[解决办法]
SELECT dbo.ReportList.*
FROM dbo.ReportList as A
where A.ReportName NOT IN (select ReportName from UserReport)

热点排行