1
0
mirror of synced 2024-12-13 22:56:04 +03:00
doctrine2/manual/docs/DQL (Doctrine Query Language) - SELECT queries - Aggregate values.php
2007-04-13 21:49:11 +00:00

17 lines
394 B
PHP

Aggregate value SELECT syntax:
<code type="php">
// SELECT u.*, COUNT(p.id) num_posts FROM User u, u.Posts p WHERE u.id = 1 GROUP BY u.id
$query = new Doctrine_Query();
$query->select('u.*, COUNT(p.id) num_posts')
->from('User u, u.Posts p')
->where('u.id = ?', 1)
->groupby('u.id');
$users = $query->execute();
echo $users->Posts[0]->num_posts . ' posts found';
</code>