SQL query to return unique dates based on different Datetime column for current date?
I have the following table (well, the example below):
CID | LogDate | RemDate
1 | 2015-05-06 | 2015-10-01
2 | 2015-05-06 | 2015-10-01
2 | 2015-05-06 | 2015-10-30
1 | 2015-01-03 | 2015-10-01
1 | 2015-01-03 | 2015-10-01
2 | 2015-04-06 | 2015-10-01
2 | 2014-04-06 | 2015-10-01
3 | 2015-05-06 | 2015-12-01
I only need to return lines that have a unique [remdate] at the current date, and ignore others, even if they have a matching [CID] ....
I expect to return to two unique rezdata ( 2015-12-01
and 2015-10-30
)
I hope I am not missing something obvious here, any help or pointers would be greatly appreciated.
source to share
If you only want to return remixes that appear once in the table, you can use aggregation for that with count
:
select remdate
from yourtable
group by remdate
having count(remdate) = 1
If you want to return those remdates that appear once after logdate
, just add this field to the sentence group by
.
source to share