Skip to content

Commit 1a2271a

Browse files
authored
Create sqlserver.sql
1 parent f0a6cba commit 1a2271a

File tree

1 file changed

+14
-0
lines changed
  • sql-queries-12/updating-rows-subquery-referencing-same-table

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Self join
2+
UPDATE P1
3+
SET P1.end_date = DATEADD(week, 3, P2.start_date)
4+
FROM Program AS P1
5+
JOIN Program AS P2
6+
ON P1.id = P2.id;
7+
8+
--Subquery within UPDATE ... SET
9+
UPDATE Program
10+
SET end_date = (
11+
SELECT DATEADD(week, 3, start_date)
12+
FROM Program AS Temp
13+
WHERE Temp.id = Program.id
14+
);

0 commit comments

Comments
 (0)