Inner Join with select columns model

Hi everybody,

I'm new in Phalcon and I don't know how to translate this query to Phalcon Query, It tooks me 3 hours with many searchs.

select sp.* FROM subplan sp INNER JOIN (SELECT sub_id, MAX(end_date) AS MaxDateTime FROM subplan WHERE status = 3 GROUP BY sub_id) groupedtt ON sp.sub_id = groupedtt.sub_id AND sp.end_date = groupedtt.MaxDateTime

Can anyone help me with that? Thank you!



31.2k

Hi,

I don't think it is possible to do that with phalcon's ORM or query builder. You will have to do that with raw sql.

Just rewrite it to just join table and do WHERE condition on select, not in join.