Selecting elements from two arrays
Create a query that joins two arrays and selects elements from both to create the
output.
Procedure
Results
The query should look like
this:
FROM order AS o
UNNEST o.items
JOIN customer AS c ON c.custid = o.custid
SELECT {
c.name,
c.rating,
o.orderno,
itemno
}
It returns the following
result:
[
{
"name": "R. Duvall",
"rating": 640,
"orderno": 1001,
"itemno": 347
},
{
"name": "R. Duvall",
"rating": 640,
"orderno": 1001,
"itemno": 193
},
{
"name": "T. Cruise",
"rating": 750,
"orderno": 1002,
"itemno": 460
},
{
"name": "T. Cruise",
"rating": 750,
"orderno": 1002,
"itemno": 680
},
{
"name": "B. Pitt",
"rating": null,
"orderno": 1003,
"itemno": 120
},
{
"name": "B. Pitt",
"rating": null,
"orderno": 1003,
"itemno": 460
},
{
"name": "J. Roberts",
"rating": 565,
"orderno": 1004,
"itemno": 680
},
{
"name": "J. Roberts",
"rating": 565,
"orderno": 1004,
"itemno": 195
},
{
"name": "T. Hanks",
"rating": 750,
"orderno": 1005,
"itemno": 460
},
{
"name": "T. Hanks",
"rating": 750,
"orderno": 1005,
"itemno": 347
},
{
"name": "T. Hanks",
"rating": 750,
"orderno": 1005,
"itemno": 780
},
{
"name": "T. Hanks",
"rating": 750,
"orderno": 1005,
"itemno": 375
},
{
"name": "R. Duvall",
"rating": 640,
"orderno": 1006,
"itemno": 680
},
{
"name": "R. Duvall",
"rating": 640,
"orderno": 1006,
"itemno": 120
},
{
"name": "R. Duvall",
"rating": 640,
"orderno": 1006,
"itemno": 460
},
{
"name": "T. Cruise",
"rating": 750,
"orderno": 1007,
"itemno": 185
},
{
"name": "T. Cruise",
"rating": 750,
"orderno": 1007,
"itemno": 680
},
{
"name": "T. Cruise",
"rating": 750,
"orderno": 1008,
"itemno": 460
}
]