Jump to content

Searching Text field full of '|' seperated numbers, how?


CalDude

Recommended Posts

Hi,
  In my MySQL 4 DB I have a text field that looks something like this:  '15|16|44|140|148|154|165|169|170|180|184|185|189'.  Many numbers separated my a '|' character, each number corresponds to a feature the user may wish to search for.  So, I will have a set of numbers like: 13,15,140,144,156, and I want the DB to return the rows with at least one of those numbers present in the text field.  Sorted by relevance, with the rows that contain more of the numbers first.  I can index this field if necessary.  How can I accomplish this?

Thanks!
Link to comment
Share on other sites

If you don't mind redesigning your table, you can change from

thing varchar,
features varchar,
Unique index on thing

to

thing varchar,
feature integer,
Non-unique index on thing (for use when updating a thing's features)
Non-unique index on feature (for searching by feature)

Then you can simply SELECT distinct thing FROM table WHERE feature IN (13,15,140,144,156);
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.