I have a string that contains number with separated by comma like below.
15,22,20,26,33,445,40,44,22,225,115,2
I want to know if a number say 15
is in that string or not.
The problem is that 15
and 115
both are a match.
Same for other number say 2
, for this case 20
, 25
, and 225
are match.
For both cases only it should return if there is 15
or 2
in the string.
I tried using like
keyword but it's not working. It also return the rows with 115
or 20, 225, 222
whille matching 15 and 2
respectively.
Can anyone suggest a regex
pattern?
Update
I have a query like below where I was using like
keyword, but I was getting wrong result for above reason.
SELECT DISTINCT A.id,A.title,A.title_hi,A.cId,B.id as cid1,A.report_type ,A.icon_img_url, A.created_at , A.news_date
FROM tfs_report_news A, tfs_commodity_master B
WHERE (',' + RTRIM(A.cId) + ',') LIKE ('%,' + B.id + ',%')
AND A.ccId = B.ccId AND A.`report_type`= "M"
AND A.isDeleted=0 AND A.isActive=1 AND B.isDeleted=0
AND B.status=1
AND A.news_date= (SELECT MAX(T.news_date)
FROM tfs_report_news T WHERE (',' + RTRIM(T.cId) + ',')
LIKE ('%,' + B.id + ',%'))
ORDER BY created_at desc, id desc limit 100;
Here tfs_report_news
has the string 15,22,20,26,33,445,40,44,22,225,115,2
as column name cId
and individual cId
like 15
or 2
is id
of tfs_commodity_master