, , , , :
( , 2 )
:
ID Brand
1 Toyota
2 Honda
3 Porsche
4. Volvo
In order to get the following result :
ID BRAND DETID PARENTID MODEL
1 Toyota 3 1 Corolla 2011
2 Honda 5 2 Civic 2006
4 Volvo - - -
3 Porcshe - - -
Then make the following selection (a slightly different syntax for the convenience of Oracle users):
SELECT m.id,
m.brand,
x.detid,
x.parentid,
x.model
FROM T_MASTER m,
T_DETAIL x,
(SELECT m.id,NVL(MAX(d.detid),1) AS max_detid
FROM T_DETAIL d, T_MASTER m
WHERE m.id = d.parentid (+)
GROUP BY m.id) y
WHERE m.id = x.parentid (+)
AND y.max_detid = NVL(x.detid,1)
AND y.id = m.id
source
share