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