I'm trying to mark the first occurrence per day of each username. I already have all concerning people marked as dupe = 1. The first for that day should get set to dupe = 2.
Like in layman's terms, If first entry of this username for this day, mark column = 2. Do for each day.
Based on this question https://stackoverflow.com/a/12065956/1811162 I can make this
Select *
from (
select * from table WHERE dupe=1 order by date desc
) x
group by date
Which returns one member of each duplicate I'm looking for, but I'd like to set that one = 2. I am having trouble making this an update statement. Or would this even work as an update statement? I only want the first member to set.
The result I want is -
Select username, dupe where dupe!= 0;
Day 1
Bob - 2
Kathy - 2
Bob - 1
Kathy - 1
Kathy - 1
Day 2
Kathy - 2
Kathy - 1
Bob - 2
Kathy - 1
What I tried is
UPDATE table set dupeflag=2 from (
select * from
from (
select * from table WHERE dupeflag=1 order by date desc
) x
group by date
)
but no luck. probably very wrong