title: how to join on the values returned from Json_array_elements in postgresql?
body: <p>Structure of "Order" table:</p>
  
  <pre><code>objectId text, 
  subOrders jsonb
  </code></pre>
  
  <p>structure of Jsonb: array of jsonb objects. eg.</p>
  
  <pre><code>[
     {
        "className":"SubOrder",
        "__type":"Pointer",
        "objectId":"tIENf1PCHO"
     },
     {
        "className":"SubOrder",
        "__type":"Pointer",
        "objectId":"yKVDFEuWx7"
     }
  ]
  </code></pre>
  
  <p>Structure of "SubOrder" table:</p>
  
  <pre><code>objectId text,
  orderitems jsonb
  </code></pre>
  
  <p>structure of suborder.orderitems jsonb, eg:</p>
  
  <pre><code>[
     {
        "className":"SubOrderItem",
        "__type":"Pointer",
        "objectId":"6d1DLrmOTD"
     },
     {
        "className":"SubOrderItem",
        "__type":"Pointer",
        "objectId":"xK6mR2PDDU"
     }
  ]
  </code></pre>
  
  <p>I need to join <code>Order.suborders.objectId</code> with <code>suborder.objectid</code></p>
  
  <p>AS Order.suborders column is a jsonb array of objects, I am taking the array elements as below.</p>
  
  <pre><code>select jsonb_array_elements("subOrders")-&gt;&gt;'objectId' 
  from "Order"
  </code></pre>
  
  <p>Then is the problem to join the returned objectId with the Suborder table.</p>