Select number of records from a table using TOP function in Teradata
Contents
Some time we wants to fetch sample rows from the table. If we use SELECT * in the query,it will bring all the rows from the table.
TOP n operator in Teradata:
Instead of fetching all rows from the table,we can use TOP n operator in the SELECT query and It will produce random ‘N’ rows from the table.
TOP n operator syntax:
1 |
SELECT TOP N * FROM Database_Name.Table_Name; |
N= Number of rows needed.
Example for TOP n operator:
Table Name: Customer (Total number of records = 7)
1 |
SELECT TOP 3 * FROM BANKING_DB.CUSTOMER; |
Since TOP 3 is mentioned in the SELECT query, It will return only 3 records from the customer table.
Output:
Similarly we can get the required number of sample records by using TOP n operator in Teradata.
Select top 10 or top 100 rows in Teradata
1 2 3 4 5 |
-- Teradata select top 10 records SELECT TOP 10 * FROM <DbName>.<TableName>; -- Teradata select top 100 records SELECT TOP 100 * FROM <DbName>.<TableName>; |
Recommended Articles