sql - MySQL pivot table - show only records of A where not in list of ids in B -


i have users table, categories table , user_category table pivot. choose multiple ids categories table generate query displays records users not in 1 of selected categories.

so if user member of 2 categories , choose exclude 1 of categories in 'not in' query, not appear in results.

here's have now:

select distinct users.id, users.firstname, users.lastname, users.email users inner join user_category on users.id = user_category.user_id user_category.category_id not in (280, 210, 177, 207, 240, 157, 187, 246, 153, 208, 199, 156, 281, 211, 212, 220, 218, 170, 201, 222, 236, 233) 

the problem is, if user in category 280 , 1 of categories did not select, still show up.

select id, firstname, lastname, email  users id not in (     select user_id     user_category     category_id in (280, 210, 177, 207, 240, 157, 187, 246, 153, 208, 199, 156, 281, 211, 212, 220, 218, 170, 201, 222, 236, 233) ) 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -