From b5754f10c736fc5402c750f2eed540b3f18c9471 Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 14 Jun 2007 14:50:14 +0000 Subject: [PATCH] --- .../order-by-clause.txt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/manual/new/docs/en/dql-doctrine-query-language/order-by-clause.txt b/manual/new/docs/en/dql-doctrine-query-language/order-by-clause.txt index d7fc05f22..2af31f34d 100644 --- a/manual/new/docs/en/dql-doctrine-query-language/order-by-clause.txt +++ b/manual/new/docs/en/dql-doctrine-query-language/order-by-clause.txt @@ -28,4 +28,29 @@ FROM User u LEFT JOIN u.Email e +++ Sorting by an aggregate value + +In the following example we fetch all users and sort those users by the number of phonenumbers they have. + +$q = new Doctrine_Query(); + +$users = $q->select('u.*, COUNT(p.id) count') + ->from('User u') + ->innerJoin('u.Phonenumber p') + ->orderby('count'); + + +++ Using random order + +In the following example we use random in the ORDER BY clause in order to fetch random post. + +$q = new Doctrine_Query(); + +$posts = $q->select('p.*, RANDOM() rand') + ->from('Post p') + ->orderby('rand') + ->limit(1) + ->execute(); + +$randomPost = $posts[0]; + +