how to fetch last entered records when i...

  • Dear,

    I have written query to select top3 records, as below

    select top 3 c_name,c_add from customers

    it is working ok.

    but when i insert new records even though it doesnt fetch new inserted records,

    I want top 3 records which are inserted last.

    is there any query like?

    select last 3 c_name,c_add from customer

    i want only 3 records which are inserted last.

    Please help me

    regards,

  • Hallo please test this i have found times ago ,

    SELECT TOP 3

    FELDA, FELDB, ...

    FROM Datenquelle

    ORDER BY ID_FELD DESC

    Greetings Thomas

  • Do you have an identity column, a time stamp column or a column that shows date entered (default getdate())? If not, there's no way to get the latest 3 rows. SQL doesn't keep any record of when a row was entered.

    If you have an identity or a date entereed then you can get top 3 order by <column> desc where <column> is your identity or date column

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply