RoyalTS
RoyalTS

Reputation: 10203

Random sample of n rows

I would like to sample n rows from a table at random. Alas

SELECT * FROME testtable sample (10 rows);

as the docs suggest gives me:

SQL compilation error: Sampling with sample missing tag for parameter seed.

Tagging on SEED(123) gives me

SQL compilation error: Sampling with sample wrong number of arguments for parameter seed.     

Upvotes: 0

Views: 2438

Answers (2)

Simon D
Simon D

Reputation: 6279

Seems to work okay for me. Are you sure that's a table you are sampling on and not a view / materialised view or anything?

If you have access to the snowflake_sample_data database could you try this and see?

select 
    * 
from snowflake_sample_data.tpch_sf1.customer sample (10 rows)
;

Upvotes: 2

Clement
Clement

Reputation: 194

If I correctly understand, you want to randomly select 10 rows from a table.

The following can help to achieve this result:

select * from testtable 
order by RANDOM(123)
limit 10;

Upvotes: 1

Related Questions