Migrate DBTNG query with JOIN and IN
Your original conditions looks in usergroup_id, while the D7 versions checks user_id?

Also, there is no duplicate() method, only distinct().

You can use something like dpm((string)$query) to debug the generated query, and dpm($query-&gt;getArguments) to get the arguments passed to it.