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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:28:30+00:00 2026-05-27T19:28:30+00:00

EDIT: I have a table with 3 rows like so. ID NAME REV 1

  • 0

EDIT:

I have a table with 3 rows like so.

ID    NAME REV
1     A    0
1     B    0
1     C    0
2     A    1
2     B    0
2     C    0
3     A    1
3     B    1

I want to find the ID wich has a particular set of Names and the REV is same
example:
Edit2: GBN’s solution would have worked perfectly, but since i do not have the access to create new tables. The added constraint is that no new tables can be created.

if input = A,B then output is 3
if input = A ,B,C then output is 1 and not 1,2 since the rev level differs in 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-05-27T19:28:31+00:00Added an answer on May 27, 2026 at 7:28 pm

    The simplest way is to compare a COUNT per ID with the number of elements in your list:

    SELECT
       ID
    FROM
       MyTable
    WHERE
       NAME IN ('A', 'B', 'C')
    GROUP BY
       ID
    HAVING
       COUNT(*) = 3;
    

    Note: ORDER BY isn’t needed and goes after the HAVING if needed

    Edit, with question update. In MySQL, it’s easier to use a separate table for search terms

    DROP TABLE IF EXISTS gbn;
    CREATE TABLE gbn (ID INT, `name` VARCHAR(100), REV INT);
    INSERT gbn VALUES (1, 'A', 0);
    INSERT gbn VALUES (1, 'B', 0);
    INSERT gbn VALUES (1, 'C', 0);
    INSERT gbn VALUES (2, 'A', 1);
    INSERT gbn VALUES (2, 'B', 0);
    INSERT gbn VALUES (2, 'C', 0);
    INSERT gbn VALUES (3, 'A', 0);
    INSERT gbn VALUES (3, 'B', 0);
    
    DROP TABLE IF EXISTS gbn1;
    CREATE TABLE gbn1 ( `name` VARCHAR(100));
    INSERT gbn1 VALUES ('A');
    INSERT gbn1 VALUES ('B');
    
    SELECT
       gbn.ID
    FROM
       gbn
       LEFT JOIN
       gbn1 ON gbn.`name` = gbn1.`name`
    GROUP BY
       gbn.ID
    HAVING
       COUNT(*) = (SELECT COUNT(*) FROM gbn1)
       AND MIN(gbn.REV) = MAX(gbn.REV);
    
    INSERT gbn1 VALUES ('C');
    
    SELECT
       gbn.ID
    FROM
       gbn
       LEFT JOIN
       gbn1 ON gbn.`name` = gbn1.`name`
    GROUP BY
       gbn.ID
    HAVING
       COUNT(*) = (SELECT COUNT(*) FROM gbn1)
       AND MIN(gbn.REV) = MAX(gbn.REV);
    

    Edit 2, without extra table, use a derived (inline) table:

    SELECT
       gbn.ID
    FROM
       gbn
       LEFT JOIN
       (SELECT 'A' AS `name`
        UNION ALL SELECT 'B' 
        UNION ALL SELECT 'C'
       ) gbn1 ON gbn.`name` = gbn1.`name`
    GROUP BY
       gbn.ID
    HAVING
       COUNT(*) = 3 -- matches number of elements in gbn1 derived table
       AND MIN(gbn.REV) = MAX(gbn.REV);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table with some rows. idClient, name, adress,country,... i want to know
I have a table with alot of rows looking something like this: id-name-date---pcs 1
I have a jqgrid where the database table has a few thousand rows, but
I have a query which returns some rows. Its column names are like: Age,
I have a function that allows users to edit a row in a table
I have this bit of JavaScript... 15 $('.ajax_edit_address').each(function() { 16 $(this).ajaxForm({ 17 target: $(this).parents('table.address').find('tr.address_header').children(':first'),
Is it possible to edit computed-column values? I have a computed-col in my table,
I have a view and it's composed of two tables. I want to edit
Edit: I have solved this by myself. See my answer below I have set
I have the table: select * from person; +----+------+---------+ | id | name |

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.