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