/*
SELECT * -- ir.pitem_revision_id As IrRev
FROM   infodba.PITEMREVISION ir
WHERE ir.puid = 'infodba' or Ir.Pitem_Revision_Id like 'RevId-%'
*/

SELECT ir.pitem_revision_id As IrRev
FROM   infodba.PITEMREVISION ir
WHERE ir.puid = :ir_puid
AND ir.psequence_id = (SELECT DISTINCT MAX(ir2.psequence_id)
  FROM infodba.PITEMREVISION ir
       INNER JOIN infodba.PITEMREVISION ir2 
         On (ir.rsequence_anchoru = ir2.rsequence_anchoru 
         or (ir2.puid = :ir_puid and ir2.rsequence_anchoru is null)
         )
   Where ir.puid = :ir_puid
 )   