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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:01:36+00:00 2026-06-18T00:01:36+00:00

I will illustrate my question with a fruit example: I have an array with

  • 0

I will illustrate my question with a fruit example:

I have an array with some values of fruit_type id’s.

$match= array("1","5","8").

I have a cell (fruit_type) in the table ‘fruit’.
The value of this cell is like this: “1,3,9”. It contains all the fruit_type id’s that belong to this row.

Now I want to make my SELECT query to return all the rows that have any, a combination of all of the id’s 1,5 or 8.

This query won’t work, because this will only work if the cell value is ‘1,5,8’ and not 1 or 5 or 8 (or a combination or all of them):

SELECT * FROM fruit WHERE fruit_type IN ('".implode("','",$match)."')

Any ideas?

EDIT (I think the question wasn’t clear enough..
So what I would like in this example is:
A query that will match ANY of the (cell) value’s 1 or 3 or 9 with ANY of the value’s from $match (1 or 5 or 8).

  • 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-18T00:01:37+00:00Added an answer on June 18, 2026 at 12:01 am

    The problem doesn’t lie in the query, but in the DB structure. You shouldn’t put multiple IDs in a single column (at least not if you want to query on it). You can get it to work, but it will always be very slow.

    Instead of the column fruit_type, you should have a table fruit_type.

    CREATE TABLE fruit_fruittype (fruit_id INT, fruit_type_id INT, PRIMARY KEY (`fruit_id`,`fruit_type_id`));
    

    Add a row for each fruit type per fruit.

    Now you easily query the fruits for types:

    SELECT fruit.* FROM fruit INNER JOIN fruit_fruittype ON fruit.id = fruit_fruittype.fruit_id WHERE fruit_type_id IN (1, 5, 8) GROUP BY fruit.id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code does not have much context, but will illustrate my question. It's a
I will use a simple example to illustrate my question. In Java, C, or
This will not work, but will illustrate my question: query = my_model.all() print query.count()
Hopefully, this fictitious example will illustrate my problem: Suppose you are writing a system
I will be using the following example to illustrate my question: class Attribute {}
Best way to illustrate my question is with this example code: class Item {}
A question that I have never solved. I will illustrate with two code samples
Let me illustrate this question with a simplified example. Assume I am building a
I will try and illustrate my question with examples, I am attempting to create
I will first illustrate my issue with some code: class ExampleClass { private Vector2

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.