Hi Vikram, One way to do it would be with the subquery.
I'm assuming your schema is: Topic: columns: Post: columns: topic_id: integer posted: timestamp relations: Topic: foreignAlias: Posts In SQL the query you are looking for looks like that: SELECT * FROM topic t INNER JOIN post p ON (t.id=p.topic_id) WHERE p.id=(SELECT id FROM post WHERE topic_id=p.topic_id ORDER BY posted DESC LIMIT 1 ); In DQL: $q = Doctrine_Query::create()->from('Topic t')->innerJoin('t.Posts p') ->where('p.id = (SELECT p2.id from post p2 where p2.topic_id=p.topic_id order by p2.posted desc limit 1)'); I hope that helps, Tomek On Feb 13, 11:06 am, SeeVik <vikramvmalhotra1...@gmail.com> wrote: > Hello all > > I am using Symfony with Doctrine plugin. > > I am making a simple bulletin board in my application. I want to find > out the last post in every topic and display the time in front of > topic. > > In Symfony, in the controller for the screen, I do this... > > $list_topics = Doctrine::getTable( "Topics" )->getLastPost(); > > In the model layer, in PostsTable.class.php, I have this.... > > public function getLastPost() > { > $q = $this->createQuery( 'a' ) > -> innerJoin( 'a.Topics t' ) > -> groupBy( 'a.topic_id' ) > -> having( 'a.posts_id = ?', ' Query to find out the posts having > maximum time for a particular topic ' ); > return $q->execute(); > > } > > Can somebody help me out with this? > > Thanks and Regards > Vikram --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---