Skip to content

Commit f3e8aaa

Browse files
authored
Create update-using-select-via-subquery-sqlserver.sql
1 parent 2525063 commit f3e8aaa

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- Method 1: Update via Subquery
2+
UPDATE Course
3+
SET is_active = (
4+
SELECT CASE
5+
WHEN Department.code = 'CS' THEN 'Yes'
6+
ELSE 'No'
7+
END
8+
FROM Department
9+
WHERE Department.id = Course.department_id
10+
);
11+
12+
-- View result
13+
SELECT * FROM Course;

0 commit comments

Comments
 (0)