Support Topics Documentation Slack YouTube Blog

Data query

Hi all,

I’m delovepping the notification on the unread messages in a chat tool.

I have 2 tables with relationship like that:

  1. “Conversation” table:

  2. “LastMessage” table:

I want to perform a query like that:
SELECT Conversation.objectId, Conversation.name, LastMessage.seen
FROM Conversation
INNER JOIN LastMessage ON Conversation.last = LastMessage.objectId; WHERE LastMessage.seen LIKE “${my id}”

Would any one can help me to translate it into Backendless data query for flutter?
Many thanks,

In plain english, do you want to load conversations where the last message is posted by a specific user?

@mark-piller
The “Conversation” table store all the conversations between 2 or many users.
The “LastMessage” table store the last message sent in a conversation.

Why do I need the “LastMessage”? Because that table has “Seen” property where I can use to track if the last message has been seen by all users or not in a conversation.

My asked query is to display all the “seen” messages.

is this comprehensive for you?

I just want to get a basic plain english description of what you need.

Based on your previous message, I have this:

"Need to get all conversations that have already been seen"

Is that correct?

Hi @mark-piller, it’s exactly what I need…
Do you have any solution suggestion?

Hello @Minh_Tuan_Vu

Try this:

DataQueryBuilder queryBuilder = DataQueryBuilder();
..whereClause = "last.seen is not null";
queryBuilder.properties = ["name", "objectId"];
queryBuilder.properties = ["last.seen"];
Backendless.data.of( "Conversation" ).find( queryBuilder );

Documentation:
General API - You can use the map drive approach or with classes
Working with Properties
Search with the Where Clause

@Vladimir_Yalovy Sorry but it’s still not working :frowning:
I tried to rewrite your query in flutter:
DataQueryBuilder q = DataQueryBuilder()
…whereClause = “users.objectId= ‘${AppPref.user.objectId}’ or users.objectId = ‘$uid’”
…properties = [‘name’]
… properties = [‘Count(users) as count’]
…groupBy = [‘users’]
…havingClause = ‘count=2’;

But always empty array.

Tried it but not working :frowning:
Do you have any other suggestion?

The where clause that Vladimir suggested is below, but in your message after you used something completely different. Are you staying on the same topic?

@mark-piller and @Vladimir_Yalovy Oh sorry, I was confused with my other topic.