同一个表,两个语句,需要两者之间的区别

时间:2013-11-19 22:18:47

标签: sql difference

我是一名非常基本的SQL Stuff的英语专业绊脚石。我已经得到了两个语句来返回我需要的结果(都来自同一个表):

select *
from Table1
where Column1 = 'Examplel' and UniqueID is not null
order by UniqueID2
  

(返回2000行)

select *
from Table1
where Column1 = 'Examplel'
and ColumnDATE between '2008-02-12 00:00:00.000' and '2013-08-15 00:00:00.000'
order by UniqueID2
  

(2001行返回)

我需要找到一条差异线,优先不滚动并比较两个结果中的所有线。帮助

2 个答案:

答案 0 :(得分:1)

将此全部作为一个语句运行:

select * from Table1 where Column1 = 'Examplel' and UniqueID is not null order by UniqueID2

except

select * from Table1 where Column1 = 'Examplel' and ColumnDATE between '2008-02-12 00:00:00.000' and '2013-08-15 00:00:00.000' order by UniqueID2

然后反过来:

select * from Table1 where Column1 = 'Examplel' and ColumnDATE between '2008-02-12 00:00:00.000' and '2013-08-15 00:00:00.000' order by UniqueID2

except

select * from Table1 where Column1 = 'Examplel' and UniqueID is not null order by UniqueID2

答案 1 :(得分:1)

select *
from Table1
where Column1 = 'Examplel'
and ColumnDATE between '2008-02-12 00:00:00.000' and '2013-08-15 00:00:00.000
and UniqueID is null
order by UniqueID2