Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

330
Views
mysql json_extract function search in all position
WHERE FIND_IN_SET(1, JSON_UNQUOTE(JSON_EXTRACT(mycolumn, '$.parent[0].child'))) > 0

this query is working

WHERE FIND_IN_SET(1, JSON_UNQUOTE(JSON_EXTRACT(mycolumn, '$.parent[*].child'))) > 0

this query is not working

but when i want to put * instead of 0 my query is not working. i want to search key in all positions. first query only shows "search key" equal to only first (0) json

this is my json in mysql column

{"parent":[ { "child":"1,3", "type":"" },{ "child":"36,41", "type":"1" },{ "child":"52", "type":"1" } ]}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use a solution like this:

SELECT * 
FROM table_name
WHERE FIND_IN_SET(1, REGEXP_REPLACE(JSON_EXTRACT(column_name, '$.parent[*].child'), '[\\[\\]\\" ]', '')) > 0

JSON_EXTRACT returns a single value or a JSON array with all found values. The JSON array is not valid to use on FIND_IN_SET. You first have to remove the [, ] and " to get the comma separated list of all found values.

You can also use JSON_SEARCH to solve this:

SELECT *
FROM table_name
WHERE JSON_SEARCH(column_name, 'one', '%,1,%', NULL, '$.parent[*].child') IS NOT NULL OR
  JSON_SEARCH(column_name, 'one', '1,%', NULL, '$.parent[*].child') IS NOT NULL OR
  JSON_SEARCH(column_name, 'one', '%,1', NULL, '$.parent[*].child') IS NOT NULL

demo on dbfiddle.uk

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!