Bug #28452 select count with alias fails
Submitted: 15 May 2007 19:20 Modified: 15 May 2007 19:56
Reporter: John Ruggentaler Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.0.27-community-nt OS:Windows
Assigned to: CPU Architecture:Any

[15 May 2007 19:20] John Ruggentaler
Description:
select count(... with alias) fails. Example:

This works:
select DISTINCT TABLE_NAME as tableName, COLUMN_NAME as columnName
 from COLUMNS;

This fails:
select count(DISTINCT TABLE_NAME as tableName, COLUMN_NAME as columnName)
 from COLUMNS;

This fails:
select count(DISTINCT(TABLE_NAME as tableName, COLUMN_NAME as columnName))
 from COLUMNS;

Error message:
>[Error] Script lines: 1-2 --------------------------
 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as tableName, COLUMN_NAME as columnName))
 from COLUMNS' at line 1 

 Warnings: ---> 
   W (1): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as tableName, COLUMN_NAME as columnName))
 from COLUMNS' at line 1
          <--- 
 [Executed: 5/15/07 2:17:01 PM CDT ] [Execution: 0/ms] 

How to repeat:
Run the above queries against the MySQL information schema database. The errors are repeatable against any table.
[15 May 2007 19:56] Sveta Smirnova
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://dev.mysql.com/doc/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Please read at http://dev.mysql.com/doc/refman/5.0/en/select.html in which parts of the SELECT atatement aliases can be used.
[7 Dec 2010 21:21] Carlos Gomes
Count does not accept a COUNT.  I have tried all the following:

select count(`pump`.*) from mytable as pump where `pump`.`type`='1';
select count(pump.*) from mytable as pump where `pump`.`type`='1';
select count(`pump`.*) from mytable as pump where pump.`type`='1';

How do I make this work?
[7 Dec 2010 21:40] MySQL Verification Team
Bug: http://bugs.mysql.com/bug.php?id=58802 marked as duplicate of this one.
[8 Dec 2010 0:07] Carlos Gomes
Your response is useless.  

Here is something that my help:

select count(alias.*) does not not work, but select count(alias.field) does.

good: select count(pump.id) from table mytable as pump good.
bad: select count(pump.*) does not work at all.