If you need it to sort on specific value
you 'll have to use
select *
from table
sample 500
order by 1;
A complete random set can be generated by using the random function as follows:
select *
from table
where random(1,3) < 3
but you are never sure how many rows you'll retrieve by this statement.
It should be interpreted as follows: next to every row a random number between 1 and 3 (so 1,2 or 3) will be set and only the rows with that random number less than 3 will be pulled out in the answer set. You can play with the limits and do sth lik where random (1,100)<67 and so on. But with this function you'll retrieve every time different rows.
Off course you could force it that it 'll retrieve always more than 500 rows and afterwards you add a sample on it
like
select *
from table
where random(1,3)<3
sample 500
I ran this query and saved the results:
SELECT *
FROM MyDB.MyTable
ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Then, I ran this query:
SELECT *
FROM MyDB.MyTable
ORDER BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
SAMPLE 100
When I look at the results of the last query, I don't get the first 100 rows from the first one. I get 100 random rows. Just curious how to actually pull the first rows.
The reason I'm asking is a person on my team was trying to run a large query (700,00 + rows), but was running out of memory when returning the data. Using queryman, we just exported the answer set to a delimited file and it worked fine.
Some remarks:
There are no _first_ 500 rows without ORDER BY, because a table is unordered.
As the name implies SAMPLE returns a different result set every time.
Regardless of the Teradata version you always can use BTEQ:
.set retcancel on;
.set retlimit = 500;
sel ....;
OLAP funtions have been introduced in V2R3.
If you want exactly 500 rows, you'll have to rank according to a UNIQUE column/column combination, if it's not unique there will be ties.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.