I have a table like this:
t1 t2 t3
1 01 M6
1 02 M6
2 01 M1
2 01 M1
2 02 M1
3 04 M4
3 04 M4
4 01 M1
4 01 M2
And I need to end up with something like this:
t1 t2 t3
1 01 M6
1 02 M6
2 01 M1
2 02 M1
3 04 M4
4 01 M1
4 01 M2
In other words, I need to:
for each t1, delete the rows that repeat themselves (leaving one of them) on t2 and at the same time have the same t3 value. If they repeat on t2 but have different t3, they won't be deleted.
Was testing with something like this but it's not quite there:
WITH cte AS (
SELECT t1,
RNum = ROW_NUMBER() OVER (PARTITION BY t2, t1 order by t3)
FROM tbl
)
DELETE FROM cte WHERE RNum > 1;