skip to Main Content

SQL Rookie here, I am trying to take a JSON argument into a stored procedure which is a JSON array [123, 124, 125] and convert the items to be used in an IN expression. I know there is JSON_EXTRACT function in SQL but not too familiar with it. This is MySql.

2

Answers


  1. You can use json_table in a subquery with in:

    select t.* 
    from tbl t 
    where t.some_val in (
        select t1.val 
        from json_table(t.js_arr, '$[*]' columns (val int path '$')) t1
    )
    

    See fiddle

    Login or Signup to reply.
  2. It’s not good idea to use JSON_TABLE, you should use MEMBER OF statement.

    JSON_TABLE creates temporary table and then you are querying all over that table to use IN statement. Instead u can use MEMBER OF which is not creating table, instead searches inside json array

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search