Jump to content

[SOLVED] Querying comma separated field, array!!


love_bug

Recommended Posts

Hi,

This is an unusual problem I have..

 

I have a field named "recipient_userids" where I store ids of users in a comma separated form,

sucha as "3323,5543,53,3235,23"

 

Now I want to select records from db, which matches a particular userid in "recipient_userids".

such as.. If I want to retrieve a record that has 53 in "recipient_userids" how do I do it?

I tried LIKE, IN syntax, but not doing the job.

 

OR is there a way to do it please share.

 

 

 

Link to comment
Share on other sites

That's because a comma separated list in a database is only really usable if you want to store and retrieve that list and you don't expect to process the list using the database. It is not possible to reliably search (for example searching for '55' would match '5543') or sort using that list.

 

The correct method if you want to search or sort the items in a list is to use a table design that stores each item in a separate row.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.