How to build the query clause in such scenario

I have tables Keyword, User, Event. Tables User and Event both have a one-to-many relation to Keyword called keywords. Now I have a User object and want to query Event table by counting the keywords of each Event object that are also in the User object’s keywords and sorting the Event objects by the count.

For example, we have the User(keywords: [“game”, “comic”]), Event(name: “event1”, keywords:[“game”, “mario”]), Event(name:“event2”, keywords:[“comic”]), Event(name: “event3”, keywords:[“game”, “comic”]), Event(name: “event4”, keywords: [“travel”]). After the query, the order will be “event3”, “event1”, “event2”, “event4” because event3 has two keywords matches, event1 and event2 have one keyword match while event4 has 0.

Is this feasible in the Backendless’s database? If so, how to build such a query?

Hello @Yupeng_Gu

Welcome to our community and thank you for trying out Backendless.

I’m happy to tell you that it is feasible with Backendless.

For example:

Example

Here you can find more information and solve any of your problems:
Search with SubQuery
COUNT
Data Filtering
Data retrieval with Sorting

Feel free to ask me any questions!

Regards,
Alexander

1 Like