Jump to content

Query Help : Fetch records having ALL values from a set


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.