TABLESAMPLE
TABLESAMPLE is an SQL operator used to retrieve a random sample of rows from a table. It enables efficient selection of a limited number of rows without scanning full table. It can improve performance when dealing with large volumes of data by providing an approximation of the full data set.
Example
Output
Explanation
The TABLESAMPLE
keyword uses the Bernoulli method to return 5% of the rows in the ‘employees’ table. The result can vary, as the Bernoulli method employs randomness in row selection.
Example
Output
Explanation
The TABLESAMPLE clause is used to return a sample percentage of rows from a table. In the example above, we are querying the SalesOrderDetail table from the Sales schema and we are asking for 10% of the rows to be returned. The output shown is a subset of the full table, representing approximately 10% of the entire data set. Please note that the actual number of rows returned by TABLESAMPLE can vary because the function is based on statistical methods.
Example
Output
Explanation
The TABLESAMPLE clause is used to perform a random sample of the table data. In the provided example, 10% of the rows from ‘employees’ table are selected randomly. The output shows the attributes of the selected employees. Results may vary because of randomness.