$q = Doctrine_Query::create() ->select('u.id, u.username') ->from('User u') ->orderBy('u.username ASC') ->limit(10); $users = $q->execute();
$q = Doctrine_Query::create() ->select('u.username, p.title') ->from('User u') ->leftJoin('u.Post p') ->orderBy('u.username ASC'); $results = $q->execute();
$q = Doctrine_Query::create() ->select('u.role, COUNT(u.id) as user_count') ->from('User u') ->groupBy('u.role'); $results = $q->execute();This query groups the results by the user's role and counts the number of users in each role. The select() method uses the COUNT() function to count the number of results for each group. In terms of package library, Doctrine_Query is part of the Doctrine ORM library for PHP.