Wouldn't a simple GROUP BY work?: SELECT Country.* FROM cake_countries AS Country JOIN cake_members AS Member ON Country.id=Member.country_id GROUP BY Country.id or SELECT Country.* FROM cake_members AS Member JOIN cake_countries AS Country on Country.id=Member.country_id GROUP BY country_id HAVING COUNT(country_id)>1
The first query should only list countries with more than 1 member, whereas the second query allows you to specify an arbitrary number of members you want filter by (e.g. countries with more than 5 members). You can probably also achieve the same thing with subqueries, but I haven't figured it out. On Jun 11, 6:41 am, cricket <zijn.digi...@gmail.com> wrote: > Using Cake 1.2.x > > Member belongsTo Country > > I want to create a select list of countries but only include those > countries that have at least one Member. The only thing I can think of > doing is to first select DISTINCT Member.country_id, then do a > find('list') and pass the first result as a condition. Does anyone > know of a better method? 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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en