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

SQL Query

I have 3 tables --- Product (prodId, Name) Country (countryId, Name) ProductValue (prodId, countryId, value)

I wish to query ProductValue.value according to prodId for every countries.

SQL Query -> "SELECT * , ( SELECT value FROM Productvalue pv WHERE pv.prodId = p.prodId AND countryId = c.countrycode ) AS value FROM Product p JOIN Countries c WHERE p.prodId =1"

How can I query in phalcon controller using execute()? Please help me that. Thanks



2.0k
edited Jul '14

this way:

$heads = $this->db->query(
            'SELECT
                h.id,
                h.name
            FROM heads h
            INNER JOIN sites_has_heads shh ON shh.head_id=h.id
            WHERE shh.site_id=?
            ORDER BY h.realname',
            array($siteId)
        )->fetchAll();

But why do not you use models?