开发者

Zend_Db_Select - Joins and Count - Possible Zend Bug?

I'm having an issue getting a COUNT() from a SQL query using Zend_Db_Table_Select, and I think it may be a possible bug because the SQL it should be generating actually works. Here's the Zend Select Query: ($this is a Zend_Db_Table, renamed to table1 in this example)

    $select = $this->select();
    $select->setIntegrityCheck(false);

    // Select Count
    $select->from($this, array("COUNT(*) as 'COUNT'"))
           ->joinLeft('users', 'table1.userID = users.userID')
           ->joinLeft('table2', 'users.anotherKey = table2.anotherKey');

    // Add Where clause after join
    $select->where('users.an开发者_运维百科otherKey = ?', $anotherKeyValue);

This gives the error:

SQLSTATE[42000]: Syntax error or access violation: 1140 
Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is 
illegal if there is no GROUP BY clause`

However, this query...

SELECT COUNT(*) AS 'count' FROM table1
    LEFT JOIN users ON table1.userID = users.userID
    LEFT JOIN table2 ON users.anotherKey = table2.anotherKey
    WHERE users.anotherKey = [anotherKeyValue]

...returns the expected results with no errors when run against the database. Any ideas whats going on, why the error, and how to get around it?


have you tried to see actual query, that zend_db produce?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜