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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:43:55+00:00 2026-05-26T12:43:55+00:00

I have a table design like so person_id | department 1 | a 1

  • 0

I have a table design like so

person_id   |   department
1           |   a
1           |   b
2           |   a
2           |   c
3           |   b
3           |   a

and would like to have a query return all of the person_id’s that belong to both department a and b. I figured it would be something along the lines of

select person_id from table group by person_id having ....

but can’t quite figure it out. Does anyone know how I can do this?

Edit: I figured out I can do the following. But it seems like a hack.

select person_id from table where department='A' or department='B' 
     group by person_id having count(1) > 1
  • 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-26T12:43:55+00:00Added an answer on May 26, 2026 at 12:43 pm
    SELECT
      person_id
    FROM
      yourTable
    WHERE
         department = 'a'
      OR department = 'b'
    GROUP BY
      person_id
    HAVING
      COUNT(DISTINCT department) = 2
    

    Note: The DISTINCT is only needed if a person can be a member of the same department more than once.

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

Sidebar

Related Questions

I have a schema design that looks like this: Table: User Row Column Family
I have a table INFO whose design is like this id - bigint Name
I want to have a database table that keeps data with revision history (like
I have taken table inside that i have taken the row. in design mode
I have a table with some styling. It's like: <table class=table_design id=cart> <tr> <td>something</td>
I have an article table which contains all the articles of my website. Design
I have three tables. The designs were like student table create table student (studID
Is there any name for the following DB table design: Basically we have generic
I have a 3 column layout using table-less design. <div id=main> <div id=left></div> <div
I have the following database design: Employee Table: Username, Name, DivisionCode Division Table: SapCode,

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.