How to select all records from one table that do not exist in another table?

Hi
I have an android app and I want to get some questions for my user to answer which is not already answered by him

there are three tables with 1:n relations
    QuestionTABLE
    UserTABLE
    and AnswerTABEL(or UQ table) which have[ a user column ,a question column , answer column ]
    if user answers a question it will be added in a new row in UQ table



     How can I achieve this in Backendless Android?

I thought of these but I don’t know how to implement it in backendless:

find all questionS in QUTABLE where user=this
find all/some questions in QuestionTABLE where question is not in questionS

or maybe better approach
find all/some question in QuestionTABLE
where THE question and thisUser in UQ is null
or
where there is no row in UQ table that : theQuestion and thisUser exists
or
where theQuestion and thisUser don’t have a row in UQ table( OR row is null or has null answer)

Thanks.

Hello,

To suggest a solution, we would need to know what relation columns you have declared in your tables. Could you please describe them?

Regards,
Mark

Hi
This is the code I used :
//////////make the answer

UserAndQuestion userAndQuestion = new UserAndQuestion();
userAndQuestion.setQuestion(question);
userAndQuestion.setAnswer(answer );
userAndQuestion.setUser(user);
////////////make a new row for the answer in table
////////////add relations in response
////////////there are two relations for any answer : one to the question and one to the user

Backendless.Data.of(UserAndQuestion.class).save(userAndQuestion, new AsyncCallback<UserAndQuestion>() {
@Override
public void handleResponse(UserAndQuestion response) {

////////////add relation to Question

Backendless.Data.of(Question.class).addRelation(
question
, “theQuestion:UserAndQuestion:n”
, " objectId = ‘" + response.getObjectId() + "’ "
, AsyncCallback<Integer>() );
////////////add relation to User

Backendless.Data.of(BackendlessUser.class).addRelation(
backendlessUser
, “theUser:UserAndQuestion:n”
, " objectId = ‘" + response.getObjectId() + "’ "
, AsyncCallback<Integer>() );
}

});
Thanks.

Hi Sasan

I think you must have table schemas like this:

Questions Table
|- answeredUsers [1:N relations to Users Table]
|- … your other columns

and when you want to find all Questions objects which are not answered by specific user you need to use this whereClause

answeredUsers.objectId != '&lt;userId&gt;'

see attached screenshots

http://support.backendless.com/public/attachments/622f30ff11236dc7d1723e3fbf8e0702.png&lt;/img&gt;

http://support.backendless.com/public/attachments/1d1a148839b57937b8d7f006370e1382.png&lt;/img&gt;

http://support.backendless.com/public/attachments/a9270e3f9a73de3c811fe83a00d8311d.png&lt;/img&gt;

Regards, Vlad

Hi ,
Thanks Vladimir , it worked for me .
You’ve been very helpful.

With appreciation,
Sasan