-1

I need to check if the value is in this JSON field

SELECT * FROM my_table WHERE JSON_EXTRACT(my_column, '$[*]') = 1

OR

SELECT * FROM my_table WHERE 1 IN (JSON_EXTRACT(my_column, '$[*]'))

My field: [1,2,3,4]

RESOLUTION WORK:

SELECT * FROM my_table WHERE JSON_SEARCH(my_column, "one", "1") IS NOT NULL
  • Pls show us what you have tried so far and what is the problem? – Serge Mar 13 '22 at 11:44
  • I tried this two query, but not work. I dont know why – Mateusz Chmielnicki Mar 13 '22 at 12:24
  • I Need SELECT IF ANY VALUE IN JSON = 1 – Mateusz Chmielnicki Mar 13 '22 at 12:29
  • If you need to test JSON for **numeric** value presence then you'd either test the values extracted from the array one-by-one or parse the array to separate values and test them. Whereas the string-type values may be easily found by JSON_SEARCH. – Akina Mar 13 '22 at 12:57
  • **What does "doesn't work" mean?** What happened when you tried it? Did you get an error message? If you did get an error, paste the entire message instead of paraphrasing. Did you get incorrect results? Did you get *no* results?  If the results were incorrect, what made them incorrect? What were you expecting instead? Did you get *any* correct results?  If so, what were they? – Andy Lester Mar 14 '22 at 14:13

1 Answers1

0
SELECT * FROM my_table WHERE JSON_SEARCH(my_column, "one", "1") IS NOT NULL