We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Count 1000 rows with this query?

I got this query, where i need to see how many matches there is, in that way I can see how many notifications is NOT seen. But - Let's say i where to count 1000 rows, is this a bad query?

$notifications = Self::query()
    ->columns(array('COUNT(Models\UsersNotifications.id) AS count', 'COUNT(seen.id) AS cnt'))
    ->leftJoin('Models\UsersNotificationsSeen', 'Models\UsersNotifications.id = seen.notificationid', 'seen')
    ->where('Models\UsersNotifications.userid = :userid:', array('userid' => $userid))
    ->limit(1)
    ->execute();


85.5k

check the mysql logs, see the query, replace the params,

in shell, phpmyadmin, workbench whatever...

explain ...query goes here ...

read what it says

edited Mar '17

Those are basic concerns and are not related to Phalcon.

P.S. It's very good to avoid using array() syntax.