I have values stored like this in a field 1,255,230,265
.
Is there a function in MySQL that will give me the second value in that string? In this case it'll be 255
.
I tried using locate
, but that does not seem to be meant for this.
I have values stored like this in a field 1,255,230,265
.
Is there a function in MySQL that will give me the second value in that string? In this case it'll be 255
.
I tried using locate
, but that does not seem to be meant for this.
Try this
select SUBSTRING_INDEX(SUBSTRING_INDEX(field_name,',',2),",",-1) from table_name
You might want to use SUBSTRING_INDEX() function.
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(field,',',2),',',-1)
FROM yourTable.
This grabs everything infront of the second comma, then grabs everything after the last comma (-1)
Try This
select * from Table1 where ',' + Nos+ ',' like '%,255,%'
Refer:
Use FIND_IN_SET() function:
SELECT *
FROM tableA
WHERE FIND_IN_SET(255, columnName)
OR
Use LIKE operator
SELECT *
FROM tableA
WHERE CONCAT(',', columnName, ',') LIKE '%,255,%'