Skip to Content
-1

Select random rows

Apr 11, 2017 at 01:23 PM

777

avatar image
Former Member

Is there some way to select a specified number of random rows from a table?

Something lieke on SQLServer?

SELECT TOP 10 PERCENT *
  FROM Table1
  ORDER BY NEWID()
SQL
10 |10000 characters needed characters left characters exceeded

Please check the documentation before posting a question.

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
avatar image
Former Member
Apr 11, 2017 at 08:35 PM
2

See also TABLESAMPLE option in SELECT from SAP HANA SQL and System Views Reference:

<tablesample_clause>

Applies the SELECT statement to a random sample of the table data.

<tablesample_clause> ::=
 TABLESAMPLE [BERNOULLI | SYSTEM] (<sample_size>)

<sample_size> ::= <exact_numeric_literal>

<sample_size> specifies the percentage of the table to be returned as a sample.

Values must be greater than 0 and less than or equal to 100. (100 returns the complete table). The goal of the TABLESAMPLE operator is to allow queries to be executed over ad-hoc random samples of tables. Samples are computed uniformly over rows in a columnar base table. Samples can either be uniform random samples (SYSTEM sampling) or uniform and independent random samples (BERNOULLI sampling). SYSTEM sampling exploits the lack of the independence requirement by sampling blocks of rows at a time, while SYSTEM sampling offers performance advantages over BERNOULLI sampling, it comes at the cost of larger variance in sample size.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

While this answer is correct please refrain from copying the documentation and rather link to it.

0
avatar image
Former Member Apr 11, 2017 at 01:27 PM
0
SELECT * FROM Table1 ORDER BY RAND() LIMIT 10;
Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Is there also an option with percent?

0