get records from A which are not in B

Options
Hi guys,

I have a first table "brands" which contains brands.
I have a second table "affiliations" which contains brand affiliations for each user.

I would like to create an API that allows me to retrieve the list of all brands (from the "brands" table) but for which the user is not yet affiliated (no entry present in the affiliation table for the given user).[image.png]
Ex : table "brands" :
id                brands_name   other fields
1 brand_     1                       xxxx
2 brand_     2                       xxxx
3 brand_     3                       xxxx

table "affiliation
user_id      brand_id      other fields
1               2                   xxxx

in my case, I want to get the brands 1 and 3 because the user is already affiliated with brand 2.

So I made a first request to retrieve the brands for the selected user from the affiliation table.
[image.png]And a second request on "brands" table to retrieve the id's of the complete brand list:

[image.png]But, after this step, i don't understand how being able to keep just the record which exist in table "brands" but not in table "affiliation".

Any help would be much appreciate! Thx in advance

Comments