Friday, August 31, 2012

How to do a DISTINCT find but also return more than 1 field

Hello,

When trying to do a DISTINCT find with only 1 field being returned everything works fine. But if I want more than just that 1 field of data returned it's no longer distinct. How can I do this?

$DistinctIp = $this->Log->find('all', array(
'conditions'=>array(
'last_usage_human >'=>date('Y-m-d H:i:s', strtotime('-15 minutes'))
),
'fields'=>array('DISTINCT Log.ip', 'Log.user_agent', 'Log.ip_name', 'Log.last_usage_human'),
'limit'=>333
));

This does not work, it's returning everything, it's no longer DISTINCT. 

Here you can see I want only rows with the DISTINCT ip field to be returned. But I want the data that's returned from more than just that field such as the: ip_name, last_usage_human fields as well. But when I do this it returns everything and doesn't constrain it to the DISTINCT.

Thanks,


Andrew

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 

No comments: