Using GROUP BY and COUNT
Jeremy Livingston <[email protected]>
| Newsgroups | gmane.comp.db.tds.freetds |
|---|---|
| Message-ID | <CACAKNbtrTvRD1YDx1Rt4VQ+rcpUT3-5nHj97ui6kyrwst+OXAA@mail.gmail.com> |
I am having trouble running a query that uses a left join, group by, and count on the table that is left joined. I am using FreeTDS v0.91 with unixODBC, PHP 5.3.10, and SQL Server 2008. I have my connection to use the 7.2 protocol. I am attempting to run the following query: SELECT COUNT(o0_.orderItemId) AS sclr0 FROM Membership m1_ LEFT JOIN OrderItem o0_ ON m1_.membershipId = o0_.membershipId GROUP BY m1_.membershipId This query only throws an error when there is a Membership that has no records in the OrderItem table. If I run this query in SQL Server itself, it runs with no issues and returns 0 for the Membership that has no OrderItems. When I try to run this query from FreeTDS, I receive this error: SQLSTATE[24000]: Invalid cursor state: 0 [FreeTDS][SQL Server]Invalid cursor state (SQLFetchScroll[0] at /builddir/build/BUILD/php-5.3.10/ext/pdo_odbc/odbc_stmt.c:537) Does anyone know why I would receive this error? I remember encountering a similar error when I was attempting to loop through two result sets at once, but this is a single query. This error only happens when I use the COUNT() function on the joined table and there is a case where there aren't any records in the joined table. This query works from FreeTDS when all Memberships have at least one record in OrderItem. Does anyone know what could be causing this issue or how I could resolve it? Thank you!