Writing a CakePHP find Join
I have a SQL query that I'm trying to convert into a CakePHP find, but I'm
not sure how to structure it... could someone please provide a little
assistance?
SELECT texts.*, people.id, people.first_name, people.last_name FROM texts
NATURAL JOIN (
SELECT person_id, MAX(id) AS id
FROM texts
WHERE texts.status = 'received'
GROUP BY person_id
) t RIGHT JOIN people ON people.id = t.person_id
WHERE texts.body is not null
AND texts.created > '$since'
AND person.counselor_id = '2'
ORDER BY texts.created DESC
Thank you!
No comments:
Post a Comment