Oracle - Over Partition

Costas

Administrator
Staff member
Doing a join to two tables bring the reference records from table2 but sometimes we would like to take only the first referenced record from table2, this cannot achieved somehow else apart using OVER PARTITION.

SQL:
SELECT opty.row_id, t2.created, t2.attrib_02
FROM siebel.s_opty opty
LEFT JOIN (
  SELECT s_opty_xm.created, s_opty_xm.par_row_id, s_opty_xm.attrib_02, ROW_NUMBER() OVER (PARTITION BY par_row_id ORDER BY created DESC) AS rn
  FROM siebel.s_opty_xm
) t2 ON opty.row_id = t2.par_row_id AND t2.rn = 1

where opty.row_id in ( 'x1', 'x2' )
 
Top