Bug #5326 subselect with group by causes incorrect ERROR 1054 (42S22): Unknown column
Submitted: 31 Aug 2004 21:25 Modified: 16 Sep 2004 16:11
Reporter: Dave Pullin (Basic Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.4gamma OS:Windows (Windows 2000/Slackware Linux)
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[31 Aug 2004 21: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 1:28] MySQL Verification Team
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 12: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 16:11] Oleksandr Byelkin
Thank you for bugreport! 
Bug is fixed, patch is pushed into our internal source repository.