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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:56:28+00:00 2026-06-10T02:56:28+00:00

I used a Java method called ‘containsAll()’ to check if ArrayLists have common content.

  • 0

I used a Java method called ‘containsAll()’ to check if ArrayLists have common content.

Let’s say I have a list A (one row), and several other lists in a MySQL table (in column ‘name’, row by row).
All lists consist of comma-separated Strings (at least one String in a list) – names or whatever.

Now, I want to check if all Strings in list A can be found in any of the rows in column ‘name’.
The result set should show all the rows in ‘name’ that match, that includes rows/lists must have all Strings in list A, and can have additional Strings.

Example I

A: ‘Mr.T’

____name_________________________________________
 'Hannibal'
 'Hannibal','Face','Murdock','Mr.T','Donald Duck'
 'Face','Donald Duck'
 'Superman','Chuck Norris','Mr.T'
_________________________________________________   

Result set: ‘Hannibal’,’Face’,’Murdock’,’Mr.T’,’Donald Duck’ -AND-
‘Superman’,Chuck Norris’,’Mr.T’


Example II

A: ‘Rocky’, ‘Mr.T’, ‘Apollo’

 ______name__________________________________________________
 'Hannibal','Face','Murdock','Donald Duck','Superman','Mr.T'
 'Rocky','Apollo','Ivan'
 'Apollo', 'Superman','Hannibal','Rocky','Mr.T','Chuck Norris'
 'Rocky','Mr.T','Apollo','Chuck Norris'
_____________________________________________________________   

Result set: ‘Apollo’, ‘Superman’,’Hannibal’,’Rocky’,’Mr.T’,’Chuck Norris’ -AND-
‘Rocky’,’Mr.T’,’Apollo’,’Cuck Norris’

I wonder if one can carry out those results using a MySQL query.
Thank you in advance.

  • 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-10T02:56:28+00:00Added an answer on June 10, 2026 at 2:56 am

    It appears you want to do an array intersection, except your array is a single column. It can be done, but it will be slow, difficult to debug and will not leverage the power of relational databases. A better way would be to change your table schema to something like this:

    Table groups

    group_id int unsigned not null auto_increment primary key,
    character_list text
    

    Table members_in_group

    group_id int unsigned not null,
    group_member varchar(45) not null
    

    Then you can query like this:

    SELECT group_id, character_list
    FROM groups g 
      JOIN members_in_groups m USING (group_id)
    WHERE m.group_member IN ('Mr. T', ...);
    

    The groups table is probably very like your current table. The members_in_groups table is the same data chopped up into easily searchable parts.

    ETA given your comment, this should work if you can guarantee that each character_list contains only one instance of each character:

    SELECT group_id, 
           SUM(CASE m.group_member IN ('Mr. T', 'Apollo', 'Rocky') THEN 1 ELSE 0 END) AS tally, 
           character_list
    FROM groups g
      JOIN members_in_groups m ON (g.group_id=m.group_id)
    GROUP BY group_id
      HAVING SUM(CASE m.group_member IN ('Mr. T', 'Apollo', 'Rocky') THEN 1 ELSE 0 END) = 3;
    

    In this case the HAVING clause must equal 3 because there are 3 members in IN ('Mr. T', 'Apollo', 'Rocky').

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

Sidebar

Related Questions

Let's say you have some Java code as follows: public class Base{ public void
I have a quick question regarding the clone() method in Java, used as super.clone()
I have the following method being called in a Java EE web application. public
IllegalStateException is often used in Java when a method is invoked on an object
I want to implement a method in java that could be used to categorize
In Java, flush() method is used in streams. But I don't understand what are
I have used java mail(com.sun.mail.smtp) from my struts project. Mail is sent successfully but
It has been a long time since I used java and I have run
I have a jar library. I used Java Class File Editor (CE) to modify
I've used exceptions in Java and like the way it won't let you call

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.