I have a MySQL table with the structure below
+------------------+------------------+----------------+
| comp_id | name | parent |
|------------------|------------------|----------------+
| 1 | comp1 | NULL |
+------------------+------------------+----------------+
| 2 | comp2 | 1 |
+------------------+------------------+----------------+
| 3 | comp3 | 2 |
+------------------+------------------+----------------+
| 4 | comp4 | 2 |
+------------------+------------------+----------------+
Assuming that no data has been inserted into the table. In other words, assuming that the table is empty how should i go about the following:
- traverse the JSON data below for entry into the table:
{
"org_name":"paradise island",
"daughters" : [
{
"org_name": "banana tree",
"daughters": [
{"org_name":"Yellow Banana"},
{"org_name":"Brown Banana"}
]
},
{
"org_name": "big banana tree",
"daughters": [
{"org_name":"green banana"},
{"org_name":"yellow banana"},
{
"org_name": "Black banana",
"daughters": [
{"org_name": "red spider"}
]
}
]
}
]
}
- what effective SQL query can I write to insert the JSON above into MYSQL database at once.
I've researched a host of resources on adjacency list model and nested models but none has been exhaustive on how inserts should be done via JSON input