I have a table of a number of issues
id, number, year, user_id
1 | 1 | 2009 | 1
2 | 2 | 2009 | 1
3 | 3 | 2009 | 1
4 | 1 | 2010 | 1
5 | 2 | 2010 | 1

and for each user_id I want to retrieve the greatest number grouped by
year.

I could solve my problem with the following query:

SELECT `Issue`.`id` AS `id`, `Issue`.`number` AS `number,
`Issue`.`year` AS `year, `Issue`.`user_id` AS `user_id` FROM `issues`
AS `Issue`
INNER JOIN (
SELECT MAX(`Issue`.`number`) AS `number`, `Issue`.`year` AS `year`
FROM `issues` AS `Issue`
WHERE `Issue`.`user_id` = 1
GROUP BY `Issue`.`year`
) AS `JoinedTable`
ON ( `Issue`.`number` = `JoinedTable`.`number`
AND `Issue`.`year` = `JoinedTable`.`year`
);

But I'm having some trouble translating that sql to cakephp so it
integrates with paginator() and find()

Could anybody give me some hints on how to solve this?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to