samshel Posted April 21, 2011 Share Posted April 21, 2011 Hi All, Need some help with a query. Following is the situation: table : user user_id user_name 1 User_1 2 User_2 3 User_3 user_categories user_id cat_id 1 1 1 2 1 3 2 1 2 2 3 1 I need to find users who belong to all three categories [1,2,3]. In this case only user_id 1 should be returned. I cannot use "IN" as it checks for any 1 value from the set. I need records which have all cats. I cannot use "AND" as one record contains only 1 category. PS: Handling in code will be easy however I need to do it in single query Any help is really appreciated. Good Day !! Link to comment https://forums.phpfreaks.com/topic/234360-query-help-fetch-records-having-all-values-from-a-set/ Share on other sites More sharing options...
fenway Posted April 24, 2011 Share Posted April 24, 2011 You need to cross join, one for each of the three conditions. Link to comment https://forums.phpfreaks.com/topic/234360-query-help-fetch-records-having-all-values-from-a-set/#findComment-1205578 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.