Can I exclude some rows with join?

Options
Hi
I have a query from which I want to exclude records based on certain condition. for example, I have a list of events and I want to exclude those events which are already followed by the user (I have follows as separate table with reference to user and to event).

So my idea was to join the follows table with condition that following user must be current user, and then in custom query create a condition that event_id =/ follows.event_id.

But it does not seems to work.[image.png]

Comments

  • Perhaps try to do it in 2 steps - first join the tables and then apply ‘filter’ from the the higher order filter to filter out results that don’t match your condition.

    https://docs.xano.com/working-with-data/lambdas-javascript/higher-order-filters#filter
  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    You can also do two queries. Get your user info, then get your follower info based on the user info. That might simplify your life. 
  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options
     But in that case I need to join the results from both queries at the end, unless I'm not thinking about the same thing.
  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
     You use the results from the first query (the user, from which you get the "followed") as an input filter (using not in) to the second query (the events)
  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options
     Ok , I see now. I used this solution in some previous endpoints, and I wanted to try how it would work with joins. Does doing it via queries is faster than via joins, or it depends?
  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
     It depends. And in this use case I think its going to be pretty small change either way. I suspect this is unlikely to be your bottleneck in the near-to-medium term. 

    Broadly, I have heard more noises about people asking questions to get more performance. SQL tuning sounds promising, but its almost always a lot of work for marginal benefit after the first couple of obvious things (adding a couple indexes and untangling complicated joins come to mind as obvious things).

    Where to find performance? Start by looking! Build faster, let the system get a bit slow, and measure where one sees that slowdown. The big performance opportunities are often much easier than one thinks. 
  • Pawel Magdanski
    Pawel Magdanski Member ✭✭✭
    Options
     Thanks, Ray. good insights.