Search code examples
sqloracle-databasewhere-clause

How can I select starting from where id equals some value after order by clause?


I want to select records starting at the row where a particular id is found after the order by and I'm not sure how to do that. Mainly because our batch processing of this data stopped at a particular id and I need to resume from that id to add that data to a file (start back pulling the data where that id is located).

Here's my query:

Select * from TABLE_A a left join TABLE_B b
       on a.TABLE_B_ID = b.TABLE_B_ID
    WHERE b.CODE is not null and b.OTHER_FIELD is not null
    ORDER BY a.TABLE_A_ID
    //STARTING WITH a.TABLE_A_ID = 344456 <---I want to do something like this. How?

Solution

  • You can just move the condition to the WHERE clause:

    SELECT * FROM TABLE_A a LEFT JOIN TABLE_B b
        ON a.TABLE_B_ID = b.TABLE_B_ID
    WHERE b.CODE IS NOT NULL
    AND b.OTHER_FIELD IS NOT NULL
    AND a.TABLE_A_ID >= 344456
    ORDER BY a.TABLE_A_ID