How to join and retrieval object?

Dear support

I have 2 tables Itinerary and Location with relation 1-1.
Itinerary Table
http://support.backendless.com/public/attachments/06f643a81f0fdc3c644fc4a4beb20308.png</img>
Location Table
http://support.backendless.com/public/attachments/1747664565e8e311800a53be18b2ae9f.png</img>

I want to query Locations which have Itineraries. Like SQL statement
“select * from location, itinerary where location.id = itenerary.location.id”

How I can do it in Backendless?

Thanks
Best Regards

Dear support

I hope this question is not missing. I need your help

Thanks
Best Regards

Hi Vu,

The following whereClause query (sent to the Itinerary table) will get you want you want:

location.objectId = ‘specific objectId of a location object’

Regards,
Mark

Hi Mark

Thanks your answer but it just for get result of itineraries base on location id.
In my case I want to load list locations which have itinerary reference.

Ex: I have 4 Locations A, B, C, D
I insert Itinerary 1 relate to A
I insert Itinerary 2 relate to B
=> I expect to get result A and B.

  • C and D not in list because not have Itinerary

In SQL I can use Inner Join to list those locations(A,B). But in backendless I not find the way to get it yet.
Hope you understand my explain.

Thanks
Best Regards

To get locations for an itinerary, you can use the following whereClause query (query must be sent to the Location table):

Itinerary[location].objectId = 'itinerary object id'

Hi Mark
Sr about my explain is not good.
I think you still not get my case. I just want to get locations is referenced to itinerary. Can you look again my tables?
Or can I “Select distinct location.id from Itinerary” so I can get list Location is referenced to itinerary.

Thanks

What I suggested will do exactly what you’re asking: getting all the locations referenced by a specific itinerary.

Not by a specific itinerary. An itinerary just only have one location.
A Location is referenced by 0…n itinerary.

I want to know If locations have itineraries or not.

Thanks your patience again.

As you can see field Itinerary.location value “United State” not have any itinerary.

http://support.backendless.com/public/attachments/5a6c5b4a4c665a1066e8d17314ad04b7.png</img>

If you want to get all locations which are referenced by any itinerary, the query will look like this:

Itinerary[location].objectId is not null

To get all locations which are NOT referenced by any itinerary, then this:

Itinerary[location].objectId is null

Hi MarkWoa thanks this is what I looking for.

It is little hard to find in your document.
Again thanks your patience. Great support

Thanks
Best Regards