File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
sql-queries-11/how-to-interpret-and-fix-the-MySQL-Error-1093 Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ -- This statement generates the Error 1093
2
+ UPDATE Program
3
+ SET end_date = (SELECT start_date FROM Program);
4
+
5
+ -- This statement fixes the Error 1093 in the preceding example using a derived table
6
+ UPDATE Program
7
+ SET end_date = (
8
+ SELECT subquery_program .start_date
9
+ FROM (
10
+ SELECT start_date
11
+ FROM Program
12
+ WHERE description = ' Major in Operating Systems'
13
+ ) AS subquery_program
14
+ );
15
+
16
+ -- This statement generates the Error 1093
17
+ UPDATE Program
18
+ SET name = (SELECT description FROM Program);
19
+
20
+ -- This set of statements fixes the Error 1093 in the preceding example using a temporary table
21
+ -- Create a temporary table
22
+ CREATE TEMPORARY TABLE IF NOT EXISTS temp_table AS
23
+ SELECT id, description
24
+ FROM Program;
25
+
26
+ -- Update the main table using the temporary table
27
+ UPDATE Program t
28
+ JOIN temp_table temp ON t .id = temp .id
29
+ SET t .name = temp .description ;
30
+
31
+ -- Drop the temporary table
32
+ DROP TEMPORARY TABLE IF EXISTS temp_table;
33
+
34
+ -- This statement fixes the Error 1093 using a self-join
35
+ UPDATE Program p1
36
+ JOIN Program p2 ON p1 .id = p2 .id
37
+ SET p1 .name = p2 .description ;
You can’t perform that action at this time.
0 commit comments