0

How would I find the differences between two select statements based on the same table? For example:

SELECT ID
FROM Table as TableA
WHERE Date = '2016-04-30'

Based on the above select statement, I want to find all the IDs that don't exist in:

SELECT ID
FROM Table as TableB
WHERE Date = '2016-03-31'
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Bud Fox
  • 37
  • 1
  • 7

2 Answers2

1
SELECT ID 
FROM Table
group by ID
having sum(case when Date = '2016-04-30' then 1 else 0 end) > 0
   and sum(case when Date = '2016-03-31' then 1 else 0 end) = 0
juergen d
  • 201,996
  • 37
  • 293
  • 362
1

The earlier answer is a smart one. This is one simple way to do it.

Select ID from Table
where Date = '2016-04-30' 
and ID not in (select ID from Table where Date = '2016-03-31')
juergen d
  • 201,996
  • 37
  • 293
  • 362
Oogway
  • 83
  • 9