Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:12:36+00:00 2026-06-10T11:12:36+00:00

This is a modification to my previously answered question I have data in the

  • 0

This is a modification to my previously answered question

I have data in the table like below:

ROLE_ID | USER_ID
------------------
 14     | USER A
 15     | USER A
 11     | USER B
 13     | USER D
 13     | USER A
 15     | USER B
 15     | USER D
 12     | USER C
 15     | USER C

I would like to get user ids that ONLY have 13 and 15. So based on the example above, I should only get back USER D

The query below was provided in my previous answer and the NOT IN part was added by me, however, that doesn’t achieve the goal..

select user_id
  from my_table
 where role_id in (13,15) AND role_id not in (11,14)
 group by user_id.
having count(distinct role_id) = 2
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:12:38+00:00Added an answer on June 10, 2026 at 11:12 am

    Assuming the combination of user_id and role_id is unique, you could do something like

    select user_id
      from my_table
     where role_id in (13,15,11,14) 
     group by user_id.
    having sum( case when role_id in (13,15) then 1 else 0 end) = 2
       and sum( case when role_id in (11,14) then 1 else 0 end) = 0
    

    If the combination of user_id and role_id is not unique, then the distinct in your original count is necessary and things get a bit more challenging.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first question in here, and I would like to ask if
I have some subroutines that I call like this myWrite($fileName, \@data) . myWrite() opens
I found this great example of horizontal parallax http://www.perandersen.no/sandbox/parallax/ The only modification I would
I would like to make an async GET request that returns back a document
I have the following two functions: $(.content).click( function() { var id = this.id; $.get(InfoRetrieve,
I have previously asked a question Marking an interest point in an image using
we need to keep track of data modification during the time on some table.
I previously asked this question under another name but deleted it because I didn't
this is a continuation of the discussion I started here . I would like
I installed a modification for my vbulletin suite and got this error Fatal error:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.