It seems that Query module and $DB global have problems with SQL aggregate functions such as MIN or MAX.
E.g. the code as this
{exp:query sql="SELECT email AS e_mail, MIN(comment_id) FROM exp_comments WHERE status = 'o' AND entry_id = '6' AND notify = 'y' AND email != '[email protected]' GROUP BY email ORDER BY comment_date DESC"}
{e_mail}, {comment_id}
{/exp:query}will leave variable {comment_id} unparsed, although without MIN it works correctly.
Similar problem exists with $DB global. E.g. the code as this
global $DB
sql="SELECT email AS e_mail, MIN(comment_id) FROM exp_comments WHERE status = 'o' AND entry_id = '6' AND notify = 'y' AND email != '[email protected]' GROUP BY email ORDER BY comment_date DESC"
$query = $DB->query($sql);
print_r($query->result);will output array with strange indexes such as these:
Array ( [0] => Array ( [email] => .(JavaScript must be enabled to view this email address) [MIN(comment_id)] => 18780 ) [1] => Array ( [email] => .(JavaScript must be enabled to view this email address) [MIN(comment_id)] => 18768 ) )I use EE 1.6.9 build 20100805 .
It seems like a bug, isn’t it?