There is a table test. The table has 2 columns: id, json_data. This table has entries:

1 {"f_20550": [77, 255, 666]} 2 {"f_20550": [77, 255]} 2 {"f_20550": [77, 66]} 

Task: to find all records for which the f_20550 property in the array has an element 77.

  • What version of mysql are you using and what type of data does json_data have ? - Alexey Ukolov
  • 2
    Json, mysql version 5.7 - Nikolay Solopov
  • 1 {"f_20550": [77, 255, 666]} 2 {"f_20550": [77, 255]} 3 {"f_20550": [77, 66]} - Nikolay Solopov
  • On good should be so SELECT JSON_SEARCH (CAST (json_data -> "$. F_20550" AS JSON), 'one', '77') from t1; but it doesn't work for me. - cheops
  • But why bring CAST (json_data -> "$. F_20550" AS JSON, if the column is JSON and so is Nikolay Solopov

1 answer 1

 SELECT * FROM test WHERE JSON_CONTAINS( `json_data`, '77', '$.f_20550'); 
  • 77 precisely in quotes for some reason. - Nikolay Solopov