Inner Joins between tables with no Relationship

Hello,

I am new to Backendless and I have read all the documentation about relations, but I can’t figure out a way to solve this problem. I have also read FAQ’s but they are targeting different situations. I need a solution for this specific case. So I have two tables Users and FriendRequst. These two tables are not in relationship with each other.

Users Table
ObjectId
Name (STRING)
Password (STRING)
Image

FriendRequest Table
toUser (STRING) // this column contains ObjectId of User to whom friend request is send
fromUser (STRING) // this column contains ObjectId of User who has send friend request
accepted (BOOLEAN)

Now I want to do two things
(1) Make a call to FriendRequest Table that gets a collection of friend requests to specific User by using its ObjectId (for example: currentUserId)

BackendlessDataQuery query = new BackendlessDataQuery();
query.setWhereClause(String.format(“toUser = ‘%s’”, currentUserId));

(2) Now I want to use some method that can get me BackendlessUser Objects for the collection of friend requests from USER Table

NOTE:
I have attached pictures of my tables to make it more clear
( Sorry if my explanation is not clear )

Hello,

You would need to compose a query with the following whereClause:

objectId IN (‘value1’, ‘value2’, ‘value3’… )

That is you would need to iterate over FriendRequest objects, and build the whereClause for the values in fromUser/toUser, then run the query against the Users table.

Regards,
Mark

Hello Mark,

Thank you for your reply, I have tried this approach but it not time efficient, if I have 500 incoming friend request to a single user. I have use another approach in SQL and that works really quick with a single call, but I don’t know if Backendless support INNER JOINS.

This is what I am using in SQL

SELECT DISTINCT u.name, u.image
FROM Users u
JOIN FriendRequest f on f.from_user = u.objectID
WHERE f.to_user = currrentUserId;

Can you please tell me if the above approach is possible to execute in Backendless?

Backendless does not support inner joins. You would need to organize your storage and data structures to optimize data retrieval.

Regards,
Mark