I have table from which I am fetching records for two time interval as written below.
Query1:
select distinct(Id)
from dbo.tableA
where datediff(hour, dtCreate, getdate()) < 24
Query2:
select distinct(Id)
from dbo.tableA
where datediff(hour, dtCreate, getdate()) < 48
and datediff(hour, dtCreate, getdate()) > 24
The query1 returns 50 records and query2 returns 45 records.
After this I want to find those records which which are not present in query2 but present in query1. Can anybody suggest me how to do this?? Thanks in advance.
Use the
EXCEPTkeyword:(Note: I got rid of the
DISTINCTs, becauseEXCEPTdoes that implicitly; but if you prefer to leave theDISTINCTs in there, for clarity’s sake, you absolutely can.)