Select few sample records from a Teradata table using Sample function
Contents
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:
1 2 3 4 5 |
SELECT * or <Column_name> FROM <Table_name> SAMPLE N; N - Number/Percentage of rows to return in the Select query. |
Table name : Customer
Example 1: Number of rows returns
1 |
SELECT * FROM BANKING_DB.CUSTOMER SAMPLE 3; |
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.
Output
Example 2: Percentage of rows returns.
1 |
SELECT * FROM BANKING_DB.CUSTOMER SAMPLE .25; |
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.
Output:
Recommended Articles
- How to fetch the top 10 records from the table in Teradata?
- How to find the duplicates in a Teradata table?