サブクエリーを使ったINをANDにする方法 ■お気に入り1、2、3のどれかを持つユーザーを探す(OR) select * from users where id in ( select user_id from user_favorites where favorite_id in (1,2,3) ) ■お気に入り1、2、3の全てを持つユーザーを探す(AND) select * from users where id in ( select user_id from user_favorites where favorite_id in (1,2,3) group by user_id having count(distinct favorite_id) = 3 ) ※user_id、favorite_idにユニーク制約があったらdistinctは不要