You can try OQL queries in mendix to do the same. Please find the below reference,
When you start using OQL, be aware that the maintainability of your project will decrease.
Mendix offers a range of operations you can perform on a list, that will suite your case too.
Have a look at this documentation page, and specifically the UNION operation. When you perform the UNION on the same list, it will return a list of the chosen object type, avoiding duplicates.
I think this fits your use case perfectly.