Sql Statement

  • Hi there,

    I have a datetime field that gets recorded in my db everytime an item is added to the table.

    I want to be able to display the last 3 records that were added to the db. how do I do this?

    Chris

  • Hi Chris,

    Some simply approach.

    DROP TABLE #Test

    CREATE TABLE #Test(ID int,MyDate DateTime)

    INSERT INTO #Test (ID,Mydate)

    SELECT 1,'2008-05-14 10:37:48.933'

    UNION ALL

    SELECT 2,'2008-05-15 10:37:48.933'

    UNION ALL

    SELECT 3,'2008-05-16 10:37:48.933'

    UNION ALL

    SELECT 4,'2008-05-17 10:37:48.933'

    UNION ALL

    SELECT 5,'2008-05-18 10:37:48.933'

    UNION ALL

    SELECT 6,'2008-05-19 10:37:48.933'

    UNION ALL

    SELECT 7,'2008-05-20 10:37:48.933'

    UNION ALL

    SELECT 8,'2008-05-21 10:37:48.933'

    SELECT Top 3 * FROM #Test ORDER BY MyDate DESC

    ---

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

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