clear markdown compare help best fiddles feedback dbanow.uk a leap of faith?
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 1451381 fiddles created (18696 in the last week).

CREATE TABLE t1 ( id int, [date] datetime NULL ) CREATE TABLE t2 ( id int, [date] datetime NULL ) INSERT INTO t1 ([id], [date]) VALUES (1, NULL), (1, NULL), (2, NULL), (2, NULL), (3, NULL) INSERT INTO t2 ([id], [date]) VALUES (1, '2001-01-01'), (1, '2001-01-02'), (2, '2001-01-03'), (2, '2001-01-04'), (3, '2001-01-05') SELECT * FROM t1 SELECT * FROM t2 SELECT * FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY id ORDER BY [date]) AS rno FROM t1) AS t INNER JOIN (SELECT *, ROW_NUMBER() OVER (PARTITION BY id ORDER BY [date]) AS rno FROM t2) AS tt ON t.id = tt.id AND t.rno = tt.rno UPDATE t SET t.[date] = tt.[date] FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY id ORDER BY [date]) AS rno FROM t1) AS t INNER JOIN (SELECT *, ROW_NUMBER() OVER (PARTITION BY id ORDER BY [date]) AS rno FROM t2) AS tt ON t.id = tt.id AND t.rno = tt.rno SELECT * FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY id ORDER BY [date]) AS rno FROM t1) AS t INNER JOIN (SELECT *, ROW_NUMBER() OVER (PARTITION BY id ORDER BY [date]) AS rno FROM t2) AS tt ON t.id = tt.id AND t.rno = tt.rno
id date
1
1
2
2
3
id date
1 2001-01-01 00:00:00.000
1 2001-01-02 00:00:00.000
2 2001-01-03 00:00:00.000
2 2001-01-04 00:00:00.000
3 2001-01-05 00:00:00.000
id date rno id date rno
1 1 1 2001-01-01 00:00:00.000 1
1 2 1 2001-01-02 00:00:00.000 2
2 1 2 2001-01-03 00:00:00.000 1
2 2 2 2001-01-04 00:00:00.000 2
3 1 3 2001-01-05 00:00:00.000 1
id date rno id date rno
1 2001-01-01 00:00:00.000 1 1 2001-01-01 00:00:00.000 1
1 2001-01-02 00:00:00.000 2 1 2001-01-02 00:00:00.000 2
2 2001-01-03 00:00:00.000 1 2 2001-01-03 00:00:00.000 1
2 2001-01-04 00:00:00.000 2 2 2001-01-04 00:00:00.000 2
3 2001-01-05 00:00:00.000 1 3 2001-01-05 00:00:00.000 1
 hidden batch(es)