1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLのJSONを複数検索

Last updated at Posted at 2017-09-12

MySQLのJSONの中を検索したくて
where {col} IN
みたいな感じで一発でできないか探したけど見つからなかった。。。

やったのはjsonのカラムが

id json_col
1 ["1","2","4"]
2 ["1","5","7"]

上記のようなテーブルデータでjsonの中を検索したい時

SELECT json_col FROM TBL 
WHERE ( JSON_SEARCH(json_col, 'ALL', '2')>0 ) OR ( JSON_SEARCH(json_col, 'ALL', '7')>0 )

みたいにJSON_SEARCHを並べる

がとりあえず。

JSON_SEARCH(json_col, 'ALL', '["2","4"]')>0
みたいにして検索できないもんですかね。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?