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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:56:30+00:00 2026-05-12T16:56:30+00:00

Whats the best way to query MySql when I want the query return all

  • 0

Whats the best way to query MySql when I want the query return all rows where at least one value in a list of values matches at least one value in a list of values?

example

If my table contains the following rows:

name         groups
item1        gr1, gr2
item2        gr1,gr2,gr3
item3        gr1,gr3

And I have a list of values: “gr3,gr4,gr5”

I want to find all the rows in my table that have at least one of the values gr3,gr4 or gr5 in its groups field.

So the query in this case should return item2 and item3

How can I construct an efficient query without looping in my script?

  • 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-12T16:56:30+00:00Added an answer on May 12, 2026 at 4:56 pm

    Personally I would suggest this isn’t the best way to structure your database. I would have a link table, something like item_groups which would hold one row for each item-group link, so what you have there would be:

    item_name         group_name
    item1        gr1
    item1        gr2
    item2        gr1
    item2        gr2
    item2        gr3
    item3        gr1
    item3        gr3
    

    This way you can simply do

    SELECT item_name FROM item_groups WHERE group_name IN ('gr3','gr4','gr5');
    

    This is what I was taught when I covered Database theory as part of my BSc, and whilst it does result in more tables, it makes searching a lot quicker and easier.
    HTH

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

Sidebar

Related Questions

Whats the best way to check if a username exists in a MySQL table?
Whats the best way to zip up files using C#? Ideally I want to
Whats the best way to read/write file properties (like author, description, etc) in C#?
Whats the best way to go about upgrading a project with major design changes...in
Whats the best way to get the current time (HH:MM:SS) using Objective-C. I would
whats the best way to get Statistics Web pages by the users visited ?
Whats the best way to convert int's, long's, double's to strings and vice versa
Whats the best way in Ruby to do something like my_array.select(n){ |elem| ... }
Whats the best way to do a RPC (Remote Procedure Call) from a webpage
I am wondering whats the best way to programmatically make rounded corners for images.

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.