React Native
...
Parse SDK (REST)
Data objects

Join Queries

8min

Join Query using Parse

Introduction

In this guide, you will perform relational queries in Parse mimicking the behavior of SQL JOIN queries using a NoSQL database.

Prerequisites

To complete this tutorial, you will need:

Goal

Query relational data stored on Back4App in SQL JOIN query fashion.

1 - Understanding the Parse.Query class

Any Parse query operation uses the Parse.Query object type, which will help you retrieve specific data from your database throughout your app. It is crucial to know that a Parse.Query will only resolve after calling a retrieve method (like Parse.Query.find or Parse.Query.get), so a query can be set up and several modifiers can be chained before actually being called.

To create a new Parse.Query, you need to pass as a parameter the desired Parse.Object subclass, which is the one that will contain your query results. An example query can be seen below, in which a fictional Profile subclass is being queried.

JS


You can read more about the Parse.Query class here at the official documentation.

2 - Save some data on Back4App

Let’s create two example classes, TableA and TableB, which will be the targets of our queries in this guide. On Parse JS Console it is possible to run JavaScript code directly, querying and updating your application database contents using the JS SDK commands. Run the code below from your JS Console and insert the data on Back4App.

Here is how the JS Console looks like in your dashboard:

Document image


Go ahead and create the classes with the following content:

JS


3 - Querying the data

Now that you have populated the classes, we can now perform the relational queries in it. Let’s begin by performing the INNER JOIN, introducing the join relational query that we will use in all of our examples. This query represents the results of two combined queries between tables A and B, returning all the records that are related by a specific condition using the Parse.Query.matchesQuery method.

JS


The INNER JOIN SQL query behavior is exactly the one achieved in our generic join relational query, so we need to print its results in the console. Remember that with a Parse.Object you can use the get method to retrieve data by using the column name.

Let’s now perform a LEFT OUTER JOIN consisting of getting all the records on TableA and showing the relational data on TableB, when available:

JS


TheRIGHT OUTER JOINis the opposite of the left one, fetching the records fromTableB.

MySQL


Finally, we have theFULL OUTER JOINwhich is the combination of the left and right inner joins:

MySQL


Conclusion

At the end of this guide, you learned how to perform on Back4App relational queries using Parse and emulating the most common SQL JOIN queries in a NoSQL database.

Updated 12 Apr 2024
Did this page help you?