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 6695763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:15:39+00:00 2026-05-26T06:15:39+00:00

The following is what I got right now, which does not work properly because

  • 0

The following is what I got right now, which does not work properly because it checks one row for two different values.

SELECT users.* 
FROM users INNER JOIN roles_users ru ON users.id = ru.user_id
WHERE ru.role_id = 1 AND ru.role_id = 2 

I would like to select all users that have two rows in roles_users. The one rows role_id should have one and the second should have role_id two.

So select all users that have two rows in the roles_users where one of them has role_id = 1 and the other has role_id = 2.

The above query selects all users that have one row in roles_users that has first one and then two, that’s why I get no results and it does not work. So how can I do this right?

  • 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-05-26T06:15:40+00:00Added an answer on May 26, 2026 at 6:15 am
    SELECT users.id
    FROM users INNER JOIN roles_users ON users.id = roles_users.user_id 
    WHERE roles_users.role_id IN (1, 2)
    GROUP BY users.id
    HAVING COUNT(*) = 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got following error... System.NullReferenceException: Object reference not set to an instance of an
I've got following method in a class, which is a custom adapter for an
I've got following problem: (c#) There is some class (IRC bot), which has method,
I've got following URL in symfony (specifics not important): /frontend_dev.php/something/25/apple ... and a routing
I've got the following situation: I want to store data, which represents, if a
I'm configuring the JPL right now, and wanna work with swi-prolog using java. I
Right now, I have a server call kicking back the following Ruby hash: {
I've got some maintenance work to do on some WPF controls, which is something
All, I've got the following code to which is basically a function that loads
So I've got the following situation: $do = mysql_query($sql); return array(data=>array(mysql_fetch_object($do)), rows=>mysql_affected_rows()); Which is

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.