Bug #2920 | Using subquery with the delete command | ||
---|---|---|---|
Submitted: | 22 Feb 2004 6:47 | Modified: | 25 Feb 2004 4:21 |
Reporter: | Fabrizio Camuso | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 4.1.1 alpha | OS: | Windows (win xp pro (without sp1)) |
Assigned to: | Peter Gulutzan | CPU Architecture: | Any |
[22 Feb 2004 6:47]
Fabrizio Camuso
[25 Feb 2004 4:21]
Alexander Keremidarski
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.mysql.com/documentation/ and the instructions on how to report a bug at http://bugs.mysql.com/how-to-report.php Additional info: Several things: * The syntax error you get is because DELETE does not allow specifying an Alias of table DELETE FROM a AS b; -> this is not allowed * You use correlated subquery in WHERE clause of DELETE. I am not sure if it is allowed by standard at all select * from a as tab1 where (select sum(sumThis) from a, b where idA=EK and tab1.idA = idA) = 0; * Even without correlated subquery MySQL will not allow you to use table you delete from in subquery. mysql> delete from a where (select sum(0) from a) = 0; ERROR 1093 (HY000): You can't specify target table 'a' for update in FROM clause Again I am not sure if standard allows this or not. * You should be able to resolve this with using Multi Table Delete Syntax MySQL implements. From Manual Chapter DELETE Syntax http://www.mysql.com/doc/en/DELETE.html DELETE [LOW_PRIORITY] [QUICK] [IGNORE] table_name[.*] [, table_name[.*] ...] FROM table-references [WHERE where_definition] or DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM table_name[.*] [, table_name[.*] ...] USING table-references [WHERE where_definition]
[25 Feb 2004 5:45]
Alexander Keremidarski
Small correction. MySQL allows correlated subquery in WHERE clause of DELETE in form of: DELETE FROM x WHERE (SELECT SUM(0) FROM y WHERE y.id = x.id) = 0; And something very important I forgot: Thank you a lot for the perfect test case.