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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:34:17+00:00 2026-05-26T03:34:17+00:00

I have a legacy database that includes a field ‘User_Defined’ containing a string describing

  • 0

I have a legacy database that includes a field ‘User_Defined’ containing a string describing which projects each record belongs to. The project IDs are comma-separated numbers in that string. For example, records might include:

2
12
22
2,12
2,8,10,12
2,12,20,120,220

The current query is something along the lines of:

SELECT tbl_species.Species_ID, 
    tbl_species.Common_Name, 
    tbl_species.User_Defined
FROM tbl_species
WHERE User_Defined LIKE '%2';

In this case, the query of course would return all the records that contain ‘2’ anywhere in the string. I’m picking on 2 here, but it can be any number passed in via a PHP variable.

My question is how can I craft the query so that it returns only those records containing 2 but not 12, 22, 120, etc.?

BTW, I realize that the proper way to fix this would be to create a lookup table to handle this relation, but if I could patch this until the next redesign, it would be great!

Thanks!

  • 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-26T03:34:18+00:00Added an answer on May 26, 2026 at 3:34 am

    Try using FIND_IN_SET:

    WHERE FIND_IN_SET('2', User_Defined)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Entity Framwork DbContexts with a legacy database. I have 2 different
I have legacy code that relies on pointers being 32-bit and want to use
I have a legacy class that I quickly want to write a couple of
I have a large chunk of legacy php code that I need to interface
I have a MySQL server with many databases that have a similar table structure.
I have a legacy code doing math calculations. It is reportedly written in QBasic,
I've written myself a nice simple little domain model, with an object graph that
Using rails 2.3.4, is it possible to pass a hint to the database optimizer?
Some time ago we took over the responsibility of a legacy code base. One
I've inherited a site with hundreds of scattered HTML and non-framework PHP files, which

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.