DKCroat
DKCroat

Reputation: 355

Self Join issue, not receiving any result

I am trying to run query where I would compare same accounts with different time stamps, I have run this query (similar, with real accounts but I am not getting any result back. Please help.

    select  t1.number , t1.created, t1.comment, t2.number , t2.created,     
    t2.comment from [aaa].[dbo].[t_table]  t1 inner join 
    (select number , created, comment from [aaa].[dbo].[table]
where created > '2017-07-06 12:00:00.000' 
    and number in (1,2,3,4,5)) t2
    on t1.number = t2.number
    where t1.created >= '2017-07-06 11:00:00.000' and 
    t1.created < '2017-07-06 12:00:00.000' and t1.number in (1,2,3,4,5);

Upvotes: 0

Views: 30

Answers (1)

TomServo
TomServo

Reputation: 7409

This

t1 inner join 
    (select number , created, comment from [aaa].[dbo].[table]
where created > '2017-07-06 12:00:00.000' 

gets rows after noon but this condition:

t1.created < '2017-07-06 12:00:00.000' 

gets rows before noon. They are mutually exclusive. No rows were created both before and after noon.

Based on what you entered in the other part of the query, perhaps you mean:

t1 inner join 
    (select number , created, comment from [aaa].[dbo].[table]
where created > '2017-07-06 11:00:00.000' 

Upvotes: 1

Related Questions