Skip to content
Advertisement

How to select certain number of rows from large query result set in Teradata sql

I am new to Teradata sql and I have a query that selects over one million rows. I want to write teradata sql to select the first 500,000 rows, then the next 500,000 rows and then the last 100,000 + rows in my data set. For the first set I know I can use SELECT * FROM QRY1 ORDER BY 1 SAMPLE 500000, but to select 5000001 to 1000000, how can I do that?
Thank you in advance for any help you can provide.

Advertisement

Answer

In Teradata, you can use rank() and qualify:

This assumes that column id can be use to sort the records.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement