An alias was previously found. (near "SUM" at position 42) this error
$qry2="SELECT count(".$rows->name.") AS count, SUM (".$rows->name.") As SUM FROM module4piechart";
Here the CODE <<< HERE THE ERROR<<<
An alias was previously found. (near "SUM" at position 42) this error
$qry2="SELECT count(".$rows->name.") AS count, SUM (".$rows->name.") As SUM FROM module4piechart";
Here the CODE <<< HERE THE ERROR<<<
Don't use keyword as alias name and follow the #San Lin Naing answer .
As per your comment error i give some clarification about that
MySQL said: Documentation #1630 - FUNCTION mydb.SUM does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual
SELECT count(HTML) AS count1 ,SUM(HTML) As SUM1 FROM module4piechart
MySQL does not accept spaces between function name and parenthesis (unless you have set SQL_MODE=IGNORE_SPACE but that gives you other undesirable side effects)
Use single quotes to escape the keywords
$qry2="SELECT count(".$rows->name.") AS 'count' ,SUM (".$rows->name.")As 'SUM' FROM module4piechart";
You have used count
and SUM
as an alias. Actually, count
and SUM
are SQL Keyword
. You should avoid using Keyword
in SQL
query.
If you want to use Keyword
as an alias by escaping, you must quoted with '
single quotation mark or "
double quotation mark. You can also use `
grave accent to escape keywords in SQLite
and MySQL
.
For your query,
$qry2="SELECT count(".$rows->name.") AS 'count' ,SUM (".$rows->name.")As 'SUM' FROM module4piechart";
and
$qry2="SELECT count(".$rows->name.") AS `count` ,SUM (".$rows->name.")As `SUM` FROM module4piechart";
may also work.
As another option, you can change alias to another name such as count_name
, sum_name
.