Bug #5326 subselect with group by causes incorrect ERROR 1054 (42S22): Unknown column
Submitted: 31 Aug 2004 23:25 Modified: 16 Sep 2004 18:11
Reporter: Dave Pullin (Basic Quality Contributor)
Status: Closed
Category:Server Severity:S2 (Serious)
Version:4.1.4gamma OS:Microsoft Windows (Windows 2000/Slackware Linux)
Assigned to: Oleksandr Byelkin Target Version:

[31 Aug 2004 23:25] Dave Pullin
Description:
mysql> select  (select b.x from AASQLbug as b where b.x=a.x)
    -> from  AASQLbug as a where a.x=2
    -> group by a.x /* group by is required for bug to show */;
ERROR 1054 (42S22): Unknown column 'a.x' in 'where clause'

How to repeat:
drop table if exists AASQLbug ;

create table AASQLbug (x int  
,primary key(x) 
 );
insert into AASQLbug values( 1),(2),(3);

select  (select b.x from AASQLbug as b where b.x=a.x) 
from  AASQLbug as a where a.x=2
group by a.x /* group by is required for bug to show */;
[1 Sep 2004 3:28] Miguel Solorzano
Verified against latest BK source tree:

mysql> select  (select b.x from AASQLbug as b where b.x=a.x)
    -> from  AASQLbug as a where a.x=2
    -> group by a.x /* group by is required for bug to show */;
ERROR 1054 (42S22): Unknown column 'a.x' in 'where clause'
mysql>
mysql> select version();
+-------------------+
| version()         |
+-------------------+
| 4.1.5-gamma-debug |
+-------------------+
1 row in set (0.00 sec)
[6 Sep 2004 14:04] Oleksandr Byelkin
ChangeSet 
  1.2001 04/09/06 13:00:24 bell@sanja.is.com.ua +6 -0 
  fixed temporary table processing expresions of subqueries and removed wrong 
restrictions of field resolving (BUG#5326)
[16 Sep 2004 18:11] Oleksandr Byelkin
Thank you for bugreport! 
Bug is fixed, patch is pushed into our internal source repository.