Join query help

  • unicodes

    25 days ago

    Hi, I have table cars, and table my_card. I want to :

    SELECT *
    FROM cars
    JOIN my_cars ON cars.id = my_cars.car_id
    WHERE my_cars.selected = TRUE;'

    It works with query on my_cars:

    'select=id,cars(*)&selected=eq.true,'

    but how to query cars and selecting based on my_cars?
  • Tom Ireland

    25 days ago

    I think you just need to change &selected=eq.true to &my_cars.selected=eq.true.
    ๐Ÿ™1
  • unicodes

    25 days ago

    I fount on internet the magic word [!inner], and it works. it function like this. query the cars, and in parameters select=star_symbol,my_cars!inner(star_symbol), then you add a new parameter named my_cars.selected = eq.true, and for major security add a new parameter my_cars.owner = eq.id_input. I would like to ask if this is safe. @Erik Beuschau i found many information you provided in query using curl, can you confirm please if this is safe?
  • unicodes

    25 days ago

    Found out that select=star_symbol,my_cars(star_symbol) is a left join, and select=star_symbol,my_cars!inner(star_symbol) is a inner join.
  • Tom Ireland

    25 days ago

    @unicodes - This is a good reference point for PostgREST if you're using Supabase.

    https://docs.postgrest.org/en/v12/references/api/resource_embedding.html#foreign-key-joins
    โค๏ธ1
  • unicodes

    25 days ago

    Thank you @Tom Ireland!
    ๐Ÿ‘1

Stop scrolling. Start building.

toddle is a visual web app builder that rivals custom code โ€” but accessible to your entire team!

Try toddle โ€” it's free!

ยฉ Copyright 2024 toddle. All rights reserved.