Jump to content

Query Help : Fetch records having ALL values from a set


samshel

Recommended Posts

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 !!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.