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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:05:37+00:00 2026-06-05T11:05:37+00:00

I have a comma separated list of numbers in a MySQL entry ‘id_user’ like

  • 0

I have a comma separated list of numbers in a MySQL entry ‘id_user’ like so:

127,130,150,12,4,7,8,9

What is the best way to find a number in this comma-separated list and (1) remove it with the comma if it’s with other numbers or (2) just remove itself if the number is by itself like:

127

Then update the MySQL entry.

So if I wanted to remove 150 from the list, it would be updated in the MySQL as:

127,130,12,4,7,8,9

I want to avoid trying to remove the id ’12’ but end up removing the ’12’s in numbers like 127 or 512

Thank you!

  • 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-05T11:05:38+00:00Added an answer on June 5, 2026 at 11:05 am

    Reading between the lines, it sounds to me like you are storing a list of foreign keys in a comma-separated string field to represent a many-to-many relationship. This is not a good idea.

    What you should do instead is create a table to store the relations.

    For example, lets say you have a table called users and you want to store friend relationships between them. What you are doing is something like this (N.B. I realised this is actually not a great example as I wrote the end but I’m sticking with it for now):

      id  |  name  |  friends
    ------+--------+-----------
      1   | Dave   |  2,4
      2   | Bob    |  1
      3   | Tom    |  4
      4   | Bill   |  1,3
    

    Whereas what it’s much better to do is something like this:

    users

      id  |  name  
    ------+--------
      1   | Dave   
      2   | Bob   
      3   | Tom    
      4   | Bill   
    

    friends

      id  |  user  |  friend
    ------+--------+----------
      1   |   1    |    2
      2   |   1    |    4
      3   |   2    |    1
      4   |   3    |    4
      5   |   4    |    1
      6   |   4    |    3
    

    To select Dave’s friends you can do

    SELECT u.*
    FROM friends f
    JOIN users u ON u.id = f.friend
    WHERE f.user = 1
    

    …and to delete the relationship between Dave and Bob (what you want to do here), you can simply do

    DELETE FROM friends
    WHERE (
      user = 1 AND friend = 2
    ) OR (
      user = 2 AND friend = 1
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a std::string containing a comma-separated list of numbers, what's the simplest
I have a comma separated list, and would like to remove the first occurrence
Condition I have comma separated list of airway bill numbers in a record in
I have a HTML form that accepts a comma separated list of tags, which
I have a string ($c) that contains a comma-separated list of settings. Some settings
I have a DB table that contains a comma separated list of ID's (ints)
How to loop through comma separated list in SQL? I have a list of
I have a very simple function that takes a list of comma separated (x,y)
I have two comma-separated selectors; .class, .foo, .bar .lorem, .ipsum, .potato I'd like to
I would like to sort elements in a comma-separated list. The elements in the

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.