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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -