MySQL FIND_IN_SET - Forum

Forum Navigation
You need to log in to create posts and topics.

MySQL FIND_IN_SET

Hi,

I need some help if someone knows to struct a query in SQL.

I want to SELECT * from a table WHERE a Column has a set of string separated by commas. Example: 12,34,23,56 and i want as result to be returned all records who has 34 . Something like that will work ?

SELECT * FROM table WHERE Column = FIND_IN_SET = ?

 

@smartmedia : SELECT * FROM table where column like "%34";

smartmedia has reacted to this post.
smartmedia

@phil78

Thanks for your answer, the contains of record may varying for example there is a possibility to have on the same record those numbers: 23,34,134,45 The LIKE % will return both 34 and 134 something i don't want. But i will test it to verify the results.

@smartmedia, I think it should be:

SELECT * FROM table WHERE FIND_IN_SET("34", Column) > 0

Or change "34" with ? for any string as a parameter.

Check this:
https://www.w3schools.com/sql/func_mysql_find_in_set.asp

Regards.

smartmedia has reacted to this post.
smartmedia

LOL it seems ChatGTP agrees (response attached as image)

Uploaded files:
  • You need to login to have access to uploads.
Darbdenral and smartmedia have reacted to this post.
Darbdenralsmartmedia
Quote from luishp on December 30, 2022, 7:07 pm

LOL it seems ChatGTP agrees (response attached as image)

It's changing the way we can use the Internet in so many ways  ;)

@luishp

Looks creepy :)

I test the

SELECT * FROM table WHERE FIND_IN_SET(?, Column) > 0

and without any single or double quotes on ? is playing. If i put any kind of quotes is not playing any of 19 SQL query.

SOLVED

Thanks again Lui, that was the difficult part of my code.

I wish u Happy new year with health, love and a lots of money for u and your family.

 

luishp has reacted to this post.
luishp

Hi..

Just an update to anyone will use FIND_IN_SET.

Keep in mind that if your filed is defined as NULL all the records who doesn't have any data in a query FIND_IN_SET(?, Column) = 0 will ignore the records that are NULL.

The solution is to define the filed as varchar or any other type that accepts empty string.

luishp has reacted to this post.
luishp