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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:41:26+00:00 2026-06-15T03:41:26+00:00

I have a MySQL table with the following structure: I want a query that

  • 0

I have a MySQL table with the following structure:

enter image description here

I want a query that would receive a group of uids (or a single uid) and then check for their existence in a closed group under a specific mid. If they exist, the query should return the mid under which they exist. For example in the table above:

('chuks.obima', 'crackhead') should return '2
('vweetah','crackhead') should return '1'
('vweetah','crackhead','chuks.obima') should return 3
('crackhead') should return an empty result
  • 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-15T03:41:27+00:00Added an answer on June 15, 2026 at 3:41 am

    I think you need something like this:

    SELECT mid
    FROM your_table
    WHERE uid in ('favour','crackhead','charisma')
    GROUP BY mid
    HAVING COUNT(*)=3
    

    EDIT: based on your second example, this is what you are looking for:

    SELECT mid
    FROM your_table
    WHERE uid in ('vweetah', 'crackhead')
    GROUP BY mid
    HAVING
      COUNT(distinct uid)=
      (select count(*)
       from (select 'vweetah' union select 'crackhead') s)
    

    or you can just substitute last subquery with the number of elements you are looking for, e.g. HAVING COUNT(distinct uid) = 2

    EDIT2: now i understand exactly what you are looking for. This should give you the correct results:

    SELECT your_table.mid, s.tot_count, count(distinct uid)
    FROM
      your_table inner join
      (select mid, seq, count(distinct uid) tot_count from your_table group by mid, seq) s
      on your_table.mid = s.mid and your_table.seq=s.seq
    WHERE your_table.uid in ('crackhead')
    GROUP BY your_table.mid
    HAVING COUNT(distinct uid)=s.tot_count AND COUNT(distinct uid)=1
    

    where the last count is equal to the number of elements you are looking for. This could be simplified like this:

    SELECT your_table.mid
    FROM your_table
    GROUP BY your_table.mid
    HAVING
      count(distinct uid)=
      count(distinct case when your_table.uid in ('vweetah','crackhead','chuks.obima') then your_table.uid end)
      and count(distinct uid)=3
    

    If the group is to considered closed if all uid are under the same seq, you also have to modify group by with: group by your_table.mid, your_table.seq and your select with SELECT distinct your_table.mid

    • 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 having the following structure: ontology_term pathway_id pathway_name I want
I have following table structure in Mysql DB Table: Mytable -------------------------------- | uid |
I have two mysql tables that have the following structure: Table 1: ---ID---------NAME------- ---1-----
I want a mysql query for following scenario I have following database structure 1]
I have the following MySQL table structure: num field company phone website 1 Gas
I have a MySQL table with a structure like the following: I'm looking for
I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have a mysql table of the following structure. So the above table stores
I have the following structure with a MySQL table: +----------------+----------------+----------+ | zipcode | city

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.