Description:
Subselect alias doesn't work in WHERE
How to repeat:
select *, (SELECT count(u.id) from k_printbody as pb, k_printhead as ph WHERE pb.pid=ph.id and pb.mid=u.id and ph.printed=1) as pc, (SELECT count(id) from k_foto WHERE uid=u.id) as fc from k_user as u where pc>0
or
select (SELECT count(u.id) from k_printbody as pb, k_printhead as ph WHERE pb.pid=ph.id and pb.mid=u.id and ph.printed=1) as pc, (SELECT count(id) from k_foto WHERE uid=u.id) as fc from k_user as u where pc>0
=> Unknown column pc in where clause.
Source tables:
CREATE TABLE `k_printhead` (
`id` int(11) NOT NULL auto_increment,
`dat` datetime default NULL,
`printby` int(11) default NULL COMMENT 'uid',
`printed` smallint(1) unsigned default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251;
CREATE TABLE `k_printbody` (
`id` int(11) NOT NULL auto_increment,
`pid` int(11) default NULL COMMENT 'print id',
`mid` int(11) default NULL COMMENT 'model id',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251;