Data Management

Joins vs. Add-ons Explained

Summary

In Xano, you can retrieve and filter data from multiple related tables using joins or add-ons. This article will guide you through understanding when to use each approach and how to implement them efficiently.

What are Joins?

Joins are an SQL functionality that allows you to combine rows from two or more tables based on a related column between them. In Xano, you can use inner, left, or right joins to filter data across multiple tables.

Inner Join

An inner join returns records that have matching values in both tables. For example, if you have a `users` table and a `companies` table, an inner join on the `company_id` column will only return users who have a corresponding company in the `companies` table.

Left Join

A left join returns all records from the left table (the table you're querying), and the matched records from the right table (the table being joined). If there are no matching records in the right table, the result will contain `null` values for those columns.

Right Join

A right join is the opposite of a left join. It returns all records from the right table (the table being joined), and the matched records from the left table (the table you're querying). If there are no matching records in the left table, the result will contain `null` values for those columns.

Implementing Joins in Xano

  1. Create a query on the table you want to filter (e.g., `users` table).
  2. In the "Filter" tab, click the pencil icon next to "Create an expression."
  3. Click "Join" and select the table you want to join (e.g., `companies` table).
  4. Define the join condition by selecting the matching columns from both tables (e.g., `users.company_id` and `companies.id`).
  5. Choose the join type (inner, left, or right).
  6. Repeat steps 3-5 to add additional joins if needed (e.g., joining the `products` table).
  7. Apply filters using columns from any of the joined tables.

What are Add-ons?

Add-ons in Xano work like a GraphQL API request, allowing you to retrieve data from related tables in a single API request. This can be useful when you need to display data from multiple tables without filtering across them.

Implementing Add-ons in Xano

  1. Create a query on the table you want to retrieve data from (e.g., `users` table).
  2. In the "Output" tab of the query settings, click "Add-on."
  3. Select the related table you want to include (e.g., `companies` table).
  4. Choose whether the relationship is a single item or a list of items.
  5. Define the join condition by selecting the matching columns from both tables (e.g., `users.company_id` and `companies.id`).
  6. Repeat steps 3-5 to add additional add-ons if needed (e.g., adding the `products` table).

When to Use Joins vs. Add-ons

Use joins when you need to filter data across multiple tables based on specific conditions. Joins are particularly useful when you want to combine data from different tables and apply filters or perform calculations on the combined dataset.

Use add-ons when you want to retrieve data from related tables without filtering across them. Add-ons are convenient when you need to display data from multiple tables in a single API response, without the need for complex filtering or calculations.

By understanding the differences between joins and add-ons, and knowing when to use each approach, you can efficiently retrieve and filter data in Xano, ensuring optimal performance and data integrity for your applications.

This transcript was AI generated to allow users to quickly answer technical questions about Xano.

Was this helpful?

I found it helpful

I need more support
Sign up for XanoSign up for Xano

Build without limits on a secure, scalable backend.

Unblock your team's progress and create a backend that will scale for free.

Start building for free