Run Query show random X rows and stop the Query

Tools & Utilities
Enthusiast

Run Query show random X rows and stop the Query

Hello @all,

I have a table with more than 100 Mio datasets and I will taste my select. I surch for an command that execute my select and when "Teradata SQL Assistant" find 100 random rows, the select command musst stop at that moment, so I must not wait for an half houre.

select
time_id,
ekp_no,
kpi_id,
base_quantity,
current_day,
count_in_time
from vw_customer_b2b_report
stop after 100 rows (not FullTableScan)

Is there a command or SQL-command in teradata??
Thanks for your help

CU cqash

Sorry for my bad english.
1 REPLY
Teradata Employee

Re: Run Query show random X rows and stop the Query

Refer to SAMPLE Clause in Teradata Data Manipulation Statements manual.

An example from the manual:

Suppose you want to see if your customers are in at least 100 cities. The SELECT statement to
do that is the following:

SELECT COUNT (DISTINCT city)
FROM (SELECT city FROM customer_table
SAMPLE 1000) TEMP;

If customer_table is large, the SAMPLE 1000 clause would not require a full scan of the table
and the sort for DISTINCT would only handle 1000 rows.

A 1000 row sample is more than 95 percent accurate for estimating if the number of distinct
values is greater than 100.

If you were to make a similar query without including the SAMPLE clause, the query would
first have to sort the large customer_table before performing the DISTINCT.