title: PostgreSQL pass value into INNER JOIN
body: <p><strong>PostgreSQL 11</strong></p>
  <p>How to pass <code>o.create_date</code> value into INNER JOIN? I need <code>Max ID</code> before <code>o.create_date</code></p>
  <pre><code>SELECT o.id,
         o.create_date               date,
         sum(oi.quantity)            qty,
         sum(oi.quantity * sp.price) total
  FROM ax_order o
           LEFT JOIN ax_order_invenotry oi on o.id = oi.order_id
           LEFT JOIN ax_inventory i on i.id = oi.inventory_id
           LEFT JOIN ax_suppliers s on s.id = o.supplier_id
           INNER JOIN ax_supplier_price sp ON (sp.inventory_id = oi.inventory_id and sp.supplier_id = o.supplier_id)
           INNER JOIN
       (
           SELECT inventory_id,
                  max(id) id
           FROM ax_supplier_price
           WHERE create_date &lt;= o.create_date
           GROUP BY inventory_id
       ) lsp ON (sp.id = lsp.id)
  WHERE o.store_id = 13
    AND o.supplier_id = 35
  GROUP BY o.id, o.create_date
  ORDER BY o.id
  </code></pre>