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

Regrading DB query in Phalcon

In Phalcon how could we get the count of 3 tables in a single query. In general we can write the subqueries and other ways also but in Phalcon how could we acheive it. Please help me on this.

Thanks in Advance.

Hi @karthik261193 you can write raw SQL using ::query() sql queries

Other way you can use count method in your models like

class Robots extends \Phalcon\Mvc\Model { }
$robots = new Robots();
echo $robots->count();
// or
Robots::count();

Count method accept an optional param array with query options

Good luck

We need some example, you can actually do without any problem using subqueries in PHQL if those subqueries return just column values like:

SELECT (SELECT COUNT(*) FROM MODEL1) as columnCount, OtherColumn FROM OTHERMODEL