[eluser]introvert[/eluser]
[quote author="OverZealous" date="1275717205"]
@The Hamburgler
I don't know how you would do that with normal SQL, but I'm guessing you would need to build up a subquery. DMZ support subqueries, so it's just a matter of being creative. The subquery example in the manual is actually pretty close to what you want.
@introvert
The (poorly named on my part) include_related_count method is a SELECT element, and therefore cannot be used in the WHERE part of a query. (This is part of the SQL design.) However, it's simply a subquery, so you should be able to build up your own subqery and use it in a where statement. If necessary, you can look at the source code for the include_related_count method to see how to build your own subquery.[/quote]
Do you have any idea how should the subquery?
The basic query is:
Code:
SELECT `keywords`.*, (SELECT COUNT(*) AS count FROM (`images`) LEFT OUTER JOIN `keywords` `keywords_subquery` ON `keywords_subquery`.`id` = `images`.`keyword_id` WHERE `keywords_subquery`.id = `keywords`.`id`) AS image_count FROM (`keywords`)
If I add:
Code:
WHERE image_count < 2
It won't work.