Aqeel Ahmad
Aqeel Ahmad

Reputation: 473

Select records older than latest 100 records from database

My issue here is that i want to populate all the records except latest 100 records in the database. What could be the best approach to accomplish this?

Upvotes: 1

Views: 356

Answers (3)

zerkms
zerkms

Reputation: 254916

SELECT *
  FROM Table
 WHERE ID < (SELECT ID
               FROM Table
           ORDER BY ID DESC
              LIMIT 99, 1)

Upvotes: 0

user319198
user319198

Reputation:

Try using limit cause

  SELECT  *
    FROM    Table 
    order by id desc 
    limit 101 , totalrecords

Here id is auto increment field of your table

Upvotes: 2

Adriaan Stander
Adriaan Stander

Reputation: 166396

How about something like

SELECT  t.*
FROM    Table t LEFT JOIN
        (
            SELECT  ID
            FROM    Table
            ORDER BY ID DESC
            LIMIT 100
        ) top100    ON   t.ID = top100.ID
WHERE   top100.ID IS NULL

Where ID would be the column to identify the order (latest) and Table from where you wish to select

Upvotes: 0

Related Questions