Bug #61376 Delete statements referencing aliases fail when no database is selected
Submitted: 1 Jun 2011 14:04 Modified: 9 May 2012 15:25
Reporter: Davi Arnaut (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.1.58, 5.5 OS:Any
Assigned to: CPU Architecture:Any
Tags: alias, Default Database, delete, multiple-table, selected database

[1 Jun 2011 14:04] Davi Arnaut
Description:
Delete and multiple-table delete statements that use alias references fail when no database is selected.

How to repeat:
mysql> SELECT VERSION();
+-------------------------------+
| VERSION()                     |
+-------------------------------+
| 5.1.58-valgrind-max-debug-log |
+-------------------------------+
1 row in set (0.00 sec)

mysql> SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| NULL       |
+------------+
1 row in set (0.00 sec)

mysql> CREATE DATABASE db1;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE TABLE db1.t1 (a INT);
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE db1.t2 (a INT);
Query OK, 0 rows affected (0.00 sec)

mysql> DELETE a1 FROM db1.t1 AS a1 WHERE a1.a = 1;
ERROR 1046 (3D000): No database selected
mysql> DELETE a1, a2 FROM db1.t1 AS a1 INNER JOIN db1.t2 AS a2 ON a1.a = a2.a;
ERROR 1046 (3D000): No database selected
mysql> 

Suggested fix:
Alias references shouldn't require a selected database name.
[10 May 2012 16:54] Sveta Smirnova
Bug #65255 was marked as duplicate of this one.
[18 May 2012 14:48] MySQL Verification Team
see also http://bugs.mysql.com/bug.php?id=65360
[12 Jul 2018 10:53] Dennis Buteyn
So... 2018 rolled over, version 5.5.56 and this bug just bit me. Is this a new record?