Select few sample records from a Teradata table using Sample function

Sample function in Teradata

The Sample function is used in the SELECT query to return the random number of rows.It allows to specify either the number of rows or percentage of rows to return from the table.

Syntax of Sample function:

Table name : Customer

Example Table in Teradata

Example 1: Number of rows returns

There are seven rows present in the customer table.Since we are specifying SAMPLE 3 in the select query,it returning the 3 rows randomly from the table as below.


Sample function returns number of rows

Example 2: Percentage of rows returns.

If we specify the percentage level after the SAMPLE keyword in the select query, it will return the specified percentage of rows from the table. For example, we are specifying .25 in the select query.

Since the total of rows in the table is 7, the output of the query is returning 2 rows that is 25% of total rows in the tables.

Also the percentage symbol(%) is not a valid qualifier in Teradata .We have to specify the percentage in decimal numbers to perform this operation.


25% of rows returned using SAMPLE function

Recommended Articles