Saturday, June 13, 2009

RRN function in DB2

While doing some ETL I have just learned a new command in DB2 called RRN, which stands for relative record number. It has probably been used a long time, but had the rownum familiarity from Oracle.

Here is an example:
Return the relative record number and employee name from table EMPLOYEE for those employees in department 10.

SELECT RRN(EMPLOYEE), LASTNAME
FROM EMPLOYEE
WHERE DEPTNO = 10