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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:43:19+00:00 2026-06-08T03:43:19+00:00

I’m sorry for the incomplete title – I need a point in the right

  • 0

I’m sorry for the incomplete title – I need a point in the right direction on this one too.
I’m trying to write a query for searching records that contain strings in a comma separated text field. I use MySql and php.

Records example:

recordID | statuses[TEXT]
1010     | 102
1011     | 100,103
1012     | 100,106,201,300

I query statues that I want to search for from another table statues_dataset

statusName | statusCode | Yes/No
name1      | 100        |   
name2      | 101        |
name3      | 102        |  Yes
name3      | 103        |
name4      | 106        |  Yes

Now I would like to find all records that contain statues 102 OR 106

I can solve this in two steps
query statues_dataset for ones I want and then concat the condition part so I basically get the next query:

SELECT * FROM table AS t
WHERE t.statuses LIKE '%201%'
OR t.statuses LIKE '%206%'

OR this one

SELECT * FROM table AS t 
WHERE FIND_IN_SET('201',t.statuses)
OR FIND_IN_SET('206',t.statuses)

I would get the result I want:

    recordID | statuses
    1010     | 102
    1012     | 100,106,201,300

Now I was wondering if there is a better way to solve this. Preferably in one query.
Or in two queries where i would create a list of values I want to searh for.
I looked at FIND_IN_SET(str,strlist) function, but the problem is I need multiple str.
Is there a function I can use so I can fill it with multiple values I want to search for?
I’ve been googling but I’m afraid I don’t know how to properly ask.

  • 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-08T03:43:21+00:00Added an answer on June 8, 2026 at 3:43 am

    I just read your post again, and you say “or” not “and”. The following query finds the records you are looking for:

    select distinct r.*
    from records r join
         statuses_dataset d
         on concat(',', r.statuses, ',') like concat('%,', d.status, ',%') and
            d.use = 'Yes'
    

    I changed the like to include commas before and after the statuses string. This allows the query to search for “,105,” instead of “105”, to prevent matching “1050” and so on.

    If you change your mind and want records that have all the statuses, then the query is a little more complicated. Here, the subquery matches first finds all records with any match on the codes. It then counts the number of matches and returns the records that match all individual codes.

    with matches as (select r.RecordId, count(distinct d.statuscode) as num_matches
                     from records r join
                          statuses_dataset d
                          on concat(',', r.statuses, ',') like concat('%,', d.status, ',%') and
                             d.use = 'Yes'
                     group by r.RecordId
                    )
    select r.*
    from records r cross join
         (select count(distinct d.statuscode) as numyes
          from statuses_dataset
          where d.use = 'Yes'
         ) ssum join
         matches m
         on r.RecordId = m.Recordid and
            m.nummatches = ssum.numyes
    

    Using of count distinct instead of count(*) just handles duplicates in the statuses table.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
In my XML file chapters tag has more chapter tag.i need to display chapters

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.