How can I display all elements from JSON Document in Mysql -
i have inserted below data column doc.
insert tbl_temp (sid, doc) values('m000001', '{"doclist": [{"pid":"f000001","name":"roi","age":"32","city":"oli","occ":"reader"}, {"pid":"f000002","name":"joi","age":"33","city":"lnd","occ":"runner"}, {"pid":"f000003","name":"kloi","age":"34","city":"nyc","occ":"writer"} ] }' )
now wanted display pids, did query below in mysql.
select sid, json_extract(doc, '$.doclist[*].pid') pid mat.tbl_temp;
but getting result -
sid shortlisted
m000001 ["f000001", "f000002", "f000003"]
but want result below
sid shortlisted m000001 "f000001" m000001 "f000002" m000001 "f000003"
also not sure why getting '[]' in output.
when run below query (for single element), worked fine
select sid, json_extract(doc, '$.doclist[0].pid') pid mat.tbl_temp;
result:
sid shortlisted m000001 "f000001"
Comments
Post a Comment