I'm not sure of the exact source of your first error (though I suspect it's #1 below), but there are three things to get out of the way before digging too deeply:
[/quote]
@TheJim
Thanks for your reply:
1. This was the first time I had found a need for subqueries. In particular, I needed an extra where() in the join_documents_locations_project query, which I could not find a way to replicate with joins (at least using DMZ - with raw SQL it would be pretty easy). Maybe there is functionality I'm unaware of.
2. This code does in fact work. DMZ's user guide contains examples in the same format - selecting a single column, then using it as a subquery. So there are no problems with that code.
3. I'd forgotten the grouping functions - thanks for pointing this out. where_not_related() does not exist! But I think you mean where_related('sme_profile', 'id !=', ...), which does work. We got there between us