Skip to content

Commit 312b738

Browse files
authored
Update fix-when-using-UPDATE-statement.sql
1 parent 73f8c21 commit 312b738

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

sql-queries-11/how-to-interpret-and-fix-the-MySQL-Error-1093/fix-when-using-UPDATE-statement.sql

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ UPDATE Program t
33
SET t.end_date = (SELECT start_date FROM Program WHERE id=t.id);
44

55
-- This statement fixes the Error 1093 in the preceding example using a derived table
6-
UPDATE Program t
7-
SET t.end_date = (
8-
SELECT subquery_program.start_date FROM (
9-
SELECT id, start_date FROM Program WHERE id=t.id
10-
) AS subquery_program
6+
UPDATE Program
7+
SET end_date = (
8+
SELECT max_start_date
9+
FROM (
10+
SELECT MAX(start_date) AS max_start_date
11+
FROM Program
12+
) AS derived_table
1113
);
1214

1315
-- This set of statements fixes the Error 1093 in the same example using a temporary table

0 commit comments

Comments
 (0)