My database have customers and orders. Customer may have many orders with different primary keys and creation dates.
I want to make a view for customers, which consist of each customer joined with their latest order (or null if customer doesn't have any order).
I tried the following
SELECT [...], c.customer_id, o.order_id
FROM customers c
LEFT OUTER JOIN [...]
LEFT OUTER JOIN [...]
[...]
LEFT OUTER JOIN orders o ON (
o.customer_id = c.customer_id
AND o.create_dt = (
SELECT MAX(create_dt) FROM orders o2 WHERE o2.customer_id = c.customer_id
)
);
But I get the the following error
a column may not be outer-joined to a subquery
I figured out Oracle doesn't support subquery in outer join. What is the correct way to implement this view? Please note this example is simplified, and necessary changes to the statement should only affect the specific join, as there are multiple other joins and conditions going on, which are not shown here for simplicity.