Consulting

Results 1 to 7 of 7

Thread: SQL query to retrieve only rows from 60000 to last row

  1. #1

    SQL query to retrieve only rows from 60000 to last row

    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

  2. #2
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,676
    Location
    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
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  3. #3
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    221
    Location
    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

  4. #4
    VBAX Tutor Mavyak's Avatar
    Joined
    Jul 2008
    Posts
    204
    Location
    If you are using SQL Server, look into the ROW_Number() function.

  5. #5
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Quote Originally Posted by Mavyak
    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

  6. #6
    VBAX Regular
    Joined
    May 2009
    Location
    Johannesburg
    Posts
    69
    Location
    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!
    Deyken
    DeezineTek
    South Africa

  7. #7

    get 10,000th row from a table

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •