Get newest user, not the first in inner join


How to I get the latest user, and not the first user that made a notification?

User is author

This is my code

$notifications = $this->modelsManager->createBuilder()
        ->columns(array('COUNT(*) as count', 'Notifications.type', 'Notifications.userid', 'Notifications.postid', 'Notifications.time', 'Users.firstname', 'Users.lastname', 'Users.profileimage', 'Posts.title', 'Posts.image'))
        ->join('Users', ' =')
        ->leftJoin('Posts', 'Notifications.postid =')
        ->groupBy(array('Notifications.postid', 'Notifications.type'))
        ->orderBy(' DESC')

        return $notifications;

Order by DESC not working ?

that query should return the last notification, but the join should be done on

Notifications.userid =

and not on author

Do you get any errors, or bad results?

My code works fine it just fetches the very first user who made a notification, i need it to display the latest user

Rememeber it's inside a group by, so if i made a notification: "Fred commented on your post" Then if another one made a notification "Bob and 1 more made a comment on your post"

But it still says "Fred and 1 more made a comment on your post"

..... Hope you understand! :-)

edited Oct '15

this might help you... as I said inside I am not a master of those queries, takes me half an hour to make it work:

my other suggestion would be:

make the query in raw php query, you know... "SELECT * FROM Bla bla bla " and post the question in stack overflow. This is how I expanded my knowlage of sub queires and I had exact same issues as you do.