PDA

View Full Version : SQL query to retrieve only rows from 60000 to last row



aravindhan_3
06-20-2009, 10:30 PM
Hi,

I need a help to write a query to get the below results.

I run this query to get first 60000 rows

select top 60000 * from Produts which is perfect.

now I want to run an sql to get the rows from 65001 till the last rows.
How do i write the query to get the results.

regards
Arvind

CreganTur
06-22-2009, 11:47 AM
The only thing I can think of is to have another query that pulls data from your main table where the PrimaryKey of the main data table <> the primary key from the other query (select top 60000).

This will ensure that you get all of the records from your main data table that don't already exist in your other query.

HTH:thumb

debauch
08-02-2009, 02:25 AM
you can query the bottom of a table too

Select top xxx * from products
order by field desc

not sure how to dynamically do it so that it stops @ 65001 though ...

I would add a primary key and just use

select * from products where 'keyfield' > 65001

Mavyak
08-03-2009, 08:57 AM
If you are using SQL Server, look into the ROW_Number() function.

stanl
08-05-2009, 02:36 AM
If you are using SQL Server, look into the ROW_Number() function.

or possibly SELECT * Skip 60000...

then there is always

SELECT ... FROM ...
WHERE [some key] NOT IN (SELECT TOP 6000 [some key FROM ...) which will probably take a while.

.02 Stan

deyken
10-07-2009, 10:47 PM
Hi There,

This may be a little late now, but I thought that I would throw in my 2 cents anyhow:

I would accomplishe it like so:

SELECT * FROM <table_name>
WHERE KeyField BETWEEN <starting Integer> AND <ending Integer>

Also, in Code you could run loops, such as:
a) If you know that you start point will be 65001 until table EOF then,
i = 65001
do
{Perform tasks on each row}
until <table_name>.EOF
loop

b) for i = 65001 to <table_name>.RecordCount - 1 Step 1
{Do you work on each record}
Next i

I hope this would help!

aravindhan_3
06-29-2010, 01:13 AM
Hi,

I would appreciate very much if you could help me on the below..

I have use teradata sql assistant 7.1. i want to get 10000th row( emp_id_ from the table.

Note: emp_id is not a primary key
I used the below one

Select
emp_id
From
emp_table
Where
emp_Id NotIn (
Select Top 9999
emp_id
From
emp_table
Where country_code = 7)

but it says TOP functions does not support in teradata.

can anyone else suggest me some answers

Regards
Arvind