I have the following SQL Postgres database table:
id fid val
401411677 3765 2019-09-06 00:00:00.000
401411677 3782 2019-09-06 00:00:00.000
401413382 3765 2019-12-20 00:00:00.000
401413382 3782 2019-12-23 00:00:00.000
401412111 3765 2019-09-20 00:00:00.000
401412111 3782 2019-09-20 00:00:00.000
In the above, an fid = 3765
represents the FirstDate
and and fid=3782
is the SecondDate
.
I am trying to filter out all the id’s where the FirstDate
and SecondDate
are equal.
So in the above example, the output would be only 401413382
, since it’s FirstDate and SecondDate values are not the same, but for the other id’s they are the same.
2
Answers
That could be achieved with windowing functions or even without:
Link to Fiddle
Using two subqueries:
See fiddle