(Untitled)

Options
Hi there,

I have 2 tables A and B. I need to gets all records of table A which does not exists in table B.

I could'nt get the way to do this. Please guide me to achieve it.

Thanks

Comments

  • Facundo Lucci
    Options
    Hi Niraj,
    Community member here. I’m not sure of the best way with limited details and context. But, assuming there is a field with unique values in table A that matches a field in table B. I would start with adding a query all records function to your stack.
    (“+” > Database Requests > Query all Records > table A)
    Then, in the Filter tab add table B “by joins” no conditionals needed. Hit save.
    Then add a conditional “by custom query” where tableA.matching_field does not equal tableB.matching_field. Hit save.
    That should return an array of what I think you are looking for.
    Lastly, I would also check out this great video that shows the true potential of add-ons and joins. https://youtu.be/3T8DQ6aAQBw
  • Niraj Chourasia
    Options
    Hi  ,
    table A unique id field is used as foreign key in table B as user id
  • Niraj Chourasia
    Options
    Hi  ,

    I tried according to your suggestion but could'nt succeed, query always returing all records of table A

    [Xano (6).png]
  • Niraj Chourasia
    Options
    anybody can look into this ?
  • Facundo Lucci
    Options

    Hey my bad I thought because it works with equals it would work with not equals. But, that’s not how joins work.

    So what you want to do is add table B as a “left” join. Then add the conditional to that join where table A.id = table B.user_id. Then add custom query where table B.user_id = null. (Just tested and it worked.)
    [F03649FC-ACDB-4B81-96BC-CAA5166428DD]
    As far I understand this will create a table “a” with all records of tableA (which is why we kept getting all the records) joined with the matching records in B based on the conditional set. If there is no match it will add null match.
  • Gi Ma
    Gi Ma Member
    Options
     Thank you for this contribution!