Multiple relations DB query

Hi,

I’ve got a question regarding the Load Objects function in codeless.

(Assume in a table, there’s a column “test_column” with a 1 to many relation)

In the where query, I can search WHERE test_column = ‘userObjectId’ and it’ll return the entries that have that user object as a relation in the test_column.

However, when I try
“”
WHERE test_column = ‘userObjectId’ AND test_column = ‘user1ObjectId’,
“”
It always returns an empty list.

Do you know how I would be able to get the entries that have both those user objects in the relation?
Reminder: it’s 1 to many so I’m looking for entries that have both objects in the relation column.

Hello @Innocent_Nwaukwa

Great question.
When you do:

WHERE test_column = 'userObjectId' AND test_column = 'user1ObjectId'

— this doesn’t return results, because each row in the relation can only match one relation object at a time → so this condition is logically impossible in a single query.

How to solve it:

  • WHERE test_column.objectId IN ('userObjectId','user1ObjectId'),
  • GROUP BY objectId,
  • HAVING COUNT(DISTINCT test_column.objectId) >= 2.

Here’s what it looks like for my case:

Regards,
Inna

I tested it but got this error:

but it works with participants.email.

Thanks a ton for putting me on the right track :saluting_face:

1 Like