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

  • Home
  • SEARCH
  • 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 594903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:00:14+00:00 2026-05-13T16:00:14+00:00

Here’s my problem. I have a many-to-many table called ‘user_has_personalities’. In my application, users

  • 0

Here’s my problem. I have a many-to-many table called ‘user_has_personalities’. In my application, users can have many personalities, and a personality can belong to many users.

The table has two integer columns, user_id and personality_id.

What I need to do is get all users that have at least all of the personalities (a set of personality_ids of variable size) which I supply to the query.

For an example, I’d like to get all users that have personalities with ids 4, 5, 7, but can also have some other personalities. But I need the query to work for a variable number of wanted personality ids, like 4, 5, 7, 9, 10 for an example.

Any ideas?

  • 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-13T16:00:14+00:00Added an answer on May 13, 2026 at 4:00 pm

    This query does the job:

    select  user_id
    from    user_has_personalities
    where   personality_id in (<list-of-personality-ids>)
    group by user_id
    having count(*) = <numer-of-items-in-IN-list>
    

    You need to supply a comma-separated list of personality ids for <list-of-personality-ids> and you also need to provide the number of items in th elist. Sticking to your example, you would get:

    select  user_id
    from    user_has_personalities
    where   personality_id in (4,5,7)
    group by user_id
    having count(*) = 3
    

    this ensures you only get users that have all these personalities.

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

Sidebar

Related Questions

Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here's a coding problem for those that like this kind of thing. Let's see
Here's an interesting problem. On a recently installed Server 2008 64bit I opened IE
Here we go again, the old argument still arises... Would we better have a
I have a jquery bug and I've been looking for hours now, I can't
Here is a link my example of the misaligned table rows Click preview in
Here’s a problem I’ve really been struggling with. I need to merge two sorted

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.