2

I have a table looking like:

uuid  investors
1     [{"type": "Organization", "uuid": "435847ec34f541c3b66615de1f346534"}, {"type": "Organization", "uuid": "8bad8a2d97ba4d3c716686244058858e"}]
2     [{"type": "Person", "uuid": "9603633439264ebfb3e46e6052055893"}, {"type": "Organization", "uuid": "a3734663f2d34893afeeda74da26683a"}]

I want to query the uuid inside the list of column investors based on if it is Organization and Person as I have to later look for those uuid in these tables.

EDIT

thanks to @tcadidot0's answer, I now can get two columns containing type value and uuid value. Here is a screenshot of the results. Now, based on type, I want to access the corresponding tables and get the whole row having this particular uuid. Following is how the tables, Organization and Person looks like:

ORGANIZATION TABLE

uuid                              name
435847ec34f541c3b66615de1f346534  XYZ

PERSON TABLE

uuid                              name
9603633439264ebfb3e46e6052055893  Bob

enter image description here

9
  • Show us your attempted query Commented Mar 6, 2020 at 8:36
  • I have no idea actually, I tried subquerying but I think it is not for my case. Commented Mar 6, 2020 at 8:37
  • What is your expected output ? Commented Mar 6, 2020 at 8:42
  • @Cid I want to get uuid from the column investors and must know if it has type: Organization or Person Commented Mar 6, 2020 at 8:45
  • 1
    Can you edit your question and show us what should be the result of that query, given the sample input Commented Mar 6, 2020 at 8:53

1 Answer 1

2

I see your data is JSON. Try this query :

SELECT JSON_EXTRACT(investors, '$**.uuid') AS `uuid`,
       JSON_EXTRACT(investors, '$**.type') AS `Type`
FROM   mytable;

Like in this fiddle : https://www.db-fiddle.com/f/8roowVBt5VY6AebWHav9hb/1

I got this answer partially from here : https://stackoverflow.com/a/45671728/10910692

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your answer, let me give it a try.
This works and returns two columns, uuid&Type, now I want to look for this uuid in other table named Organization or Person. Can I do that using subquerying? or is there a better way? Thank you!
I'm not sure how exactly but you can add WHERE JSON_EXTRACT(investors, '$**.type') LIKE '%Person%' or something like that. I think with this example you can edit your question with your expected output to make us better understand. Just make a screenshot on spreadsheet etc. to illustrate how do you want the result returned.
Thank you again. I edited my question, please have a look.

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.