Table join producing duplicates?

Options

Hey there! I'm querying a database of users and a database of pages where each page is assigned to a user via a user id. I want to select users whose pages fit a particular conditional, so I'm using an inner join with the following standard condition:

user.id == page.user_id

However, the result of this join is that each user that matches the condition appears as a duplicate dozens of times. In SQL, I've encountered this before, and I would normally tinker with the ON condition or add a DISTINCT somewhere, but I'm not sure how to do any of those things in Xano. I can remove duplicates manually with an JS lambda but because the data is paginated, I can only remove the duplicates from the one page that's returned, resulting in only one or two results per page instead of 10 or so. What are some things I can do to fix this?

Tagged:

Best Answer

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Answer ✓
    Options

    There are multiple options, but you might try running sequential queries. For example, do a list of pages that meet your criteria. Get the userids list. Then run a get all records from the users where the id is "in" the userids list from the first query. Your pagination goes on the second query, and that's what you return. Because you're pulling a list of users in the second query, they'll be distinct!

Answers

  • Owsteen
    Owsteen Member
    Options

    This started happening to me recently. My joins started returning duplicates in the last couple weeks. Is this new?

    I used a method to filter for unique's but I have to go through all of my API's now. Does anybody know if anything changed and if this is expected behavior?