Data Management

Customer Corner: Return Items Not In a List

Hey there! In this guide, we'll explore two methods to find courses that a user is not enrolled in using the Xano no-code platform. Let's dive right in!

Method 1: Using Joins, Evals, and Custom Queries

This approach utilizes Xano's built-in features to combine tables and perform conditional queries. Follow these steps:

  1. Create a new function in the Function Stack.
  2. Query the courses table as the primary table.
  3. Set up Joins:
  • Add an inner join with the users table, where the user ID equals the authorized user ID (for authentication purposes).
  • Add a left join with the list of course IDs the user is subscribed to. This ensures that all course IDs are included, even if the user is not subscribed to them.
  • Set the condition for the left join: user_courses.id = courses.id
  1. Add an Eval to return the user_courses.id from the left join. This will be used to identify the courses the user is not subscribed to.
  2. Create a Custom Query to filter the results where the user_courses.id is null. This will give us the courses the user is not enrolled in.

That's it! When you run the function, you'll see the list of courses the authenticated user is not subscribed to.

Method 2: Querying User Record and Courses Table

This approach is a bit more straightforward but involves multiple steps:

  1. Query the user record based on the authorized user ID.
  2. Query the courses table.
  3. Add a Custom Query that checks if the course.id is not present in the list of user.course_ids from the user record.

While this method is more direct, it requires an additional step compared to the first approach.

Both methods are valid, so choose the one that suits your needs or preferences better.

Remember, these examples assume you have the necessary data models (users and courses tables) set up in your Xano project. Feel free to adjust the queries based on your specific data structure.

That's it! You now know two methods to find courses a user is not enrolled in using Xano. If you have any questions or need further assistance, don't hesitate to reach out to the Xano community or support channels.

Sign up for Xano

Join 100,000+ people already building with Xano.

Start today and scale to millions.

Start building for free