1

Seofilter db table has json column named category_ids. I wanna query where value exists in json col.

And not querying all the row and get their jsoncol value then explode etc, I wanna do it with less query to server because of server loads.

for example [{60, 59, 57}] or [{55, 58, 60}] so 60 exists both of them.

3
  • Provide a proper table structure and example data on www,sqlfiddle.com.. Also share your MySQL version with SELECT VERSION() Commented May 19, 2018 at 10:32
  • "And not querying all the row and get their jsoncol value then explode etc, I wanna do it with less query to server because of server loads." Indexing JSON data is pretty limited in MySQL.. Because you can only index datatypes like a int, double, float or string with generated columns in MySQL.. You can't index a JSON array type an search it. Commented May 19, 2018 at 10:34
  • That's not valid JSON. Do you mean [55, 58, 60]? Commented May 19, 2018 at 12:48

2 Answers 2

2

Laravel 5.6.24 includes whereJsonContains():

DB::table('seofilter')->whereJsonContains('category_id', 60)->get();
DB::table('seofilter')->whereJsonContains('category_id', [60, 61, ...])->get();
Sign up to request clarification or add additional context in comments.

Comments

0

MySQL has a group of JSON manipulating and searching function i believe you are going to find what you want over here start with JSON_CONTAINS https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#function_json-contains
which clearly fits the example you provided .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.