1

I have a column in a table that contains some number offsets like this:

my_offsets
[1,2,10,11,111,112]

I want query this rows for search value 11 in [1,2,10,11,111,112]. How can I do in SQL(mysql)?

zabitstack
  • 155
  • 1
  • 6
  • 11 in a varchar(299). Can I use IN operator in a string of numbers separated by comma? I don't think but I will test it. Thanks – zabitstack Dec 15 '22 at 14:17
  • 1
    It seems JSON_CONTAINS('[1,2,3,4,5]','1','$') Returns: 1 is correct answer! I will test it now. – zabitstack Dec 15 '22 at 14:21
  • `Can I use IN operator in a string of numbers separated by comma` will not work `[1,2,10,11,111,112]` can be `[1,2,10,11]` or `[11,111,112]` or `[11]` and then you're screwed. – Blag Dec 15 '22 at 14:21

1 Answers1

0

if data is table

SELECT my_offsets
FROM my_tab
WHERE my_offsets='11'

if data is JSON

SELECT * from my_table
WHERE JSON_CONTAINS(yur_data, '11', '$');

example

  JSON_CONTAINS('[1,2,3]','3','$') Returns: 1
  JSON_CONTAINS('[1,2,3]','7','$') Returns: 0
Michael K
  • 107
  • 1
  • 3