Jump to content

Get a unique id from a comma separated string


mapleleaf

Recommended Posts

I have a field in the database with ids in it.

Eg 3 fields below:

1,43,89,4,923

55,14, 402,77

44,8,23

 

How do I search for only the id 4 and not return 44, 43, 14, 402 etc?

 

In this case i want only the first row returned.

 

I am sure MYSQL will have someting for this.

 

Thanks

Link to comment
Share on other sites

I am not sure whether regex will work for this as I need the query to be able to find any id 2 or 22 or 32 etc.

 

For FIND IN SET I am struggling to write a query that might work. Seems like it needs subqueries which I am not familiar with.

 

i am trying something like this:

 

SELECT IN SET( '6', '( SELECT second_theme FROM articles WHERE second_theme LIKE ' %6 % ')' )
FROM articles

 

Any ideas much appreciated

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.