Teradata TOP n Operator

Teradata TOP n Operator

TOP n operator can be used to return specific number/percentage of rows from the query resultset. TOP n operator can be used in 3 ways: General Syntax: TOP n [PERCENT | WITH TIES]


➠ Restrictions for the TOP n operator
TOP n :Value of n must be positive integer.

TOP n PERCENT: Number of rows to be returned are determined by a formula ((n * number of rows in table) / 100). Value of n can be positive integer or positive decimal.

TOP n WITH TIES: This is generally used in places where ranks are determined using TOP n function and there is possibility of ties in the ranked resultset.

SELECT TOP 2 WITH TIES emp_no,salary FROM tutorial_db.employee ORDER BY salary DESC;

Output:
 emp_no   salary
-------  -------
1000245  5000.00
1000288  3000.00
1000292  3000.00



TOP n operator vs QUALIFY RANK / QUALIFY ROW_NUMBER