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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:52:32+00:00 2026-06-05T21:52:32+00:00

I have a MySQL table like so; foo bar 1 21 23 17 31

  • 0

I have a MySQL table like so;

foo      bar
1        21
23       17
31       17
23       21
19       9
23       4
31       4
3        27
51       6
31       44
23       44
31       71

What I want is to select all the unique values of bar that correspond to both 23 and 31 in the foocolumn.

i.e. for this table, I’d get the following result;

bar
17
4
44

17, 4, and 44 all get selected, since for all of those values, two rows exist that correspond to both 23 and 31 in the foo column.

Even though the values 21 and 71 in bar correspond to 23 and 31 in foo, they would not get selected, since the same value of bar isn’t present on another row that would correspond to the other number.

How would I go about this?

  • 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-05T21:52:34+00:00Added an answer on June 5, 2026 at 9:52 pm
    SELECT 
        bar
    FROM 
        tbl
    WHERE
        foo IN (23,31)
    GROUP BY
        bar
    HAVING
        COUNT(*) = 2
    

    The 2 in COUNT(*) represents the amount of values of foo you’re checking on — in this case, two. If you wanted bars corresponding to all of (23,31,7) for example, change it to COUNT(*) = 3 because there are three values to satisfy.

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

Sidebar

Related Questions

I have a MySQL table that looks like this: `id` int(10) unsigned NOT NULL
I have a mySQL table that has a column like this: ID ----- 0352
Let's say I have a MySQL table that is something like this: software table:
In MySQL, I have a simple "SELECT * FROM foo" query. I would like
I have a main table foo with dates and values, and a table bar
If i have data in my MySQL like this table: data(TEXT) foo (hal) foo
I have a table like this: column_a column_b foo 1 bar 1 bar 2
I have an insert query for MySQL that looks like this: INSERT INTO table
I have a 2 MySQL tables like that: Table: WIFI_Spots ********************* ID | Name
I have a MySQL table like this: Payments +----+---------------------+---------+ | id | date (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.