most recent output

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TJM

    most recent output

    hello,

    I have a table which contains the audit time field. This audit time field
    records the current date and time when a record is inserted.
    I would like to output the most recent top 500 rows.
    thank you.



  • Hugo Kornelis

    #2
    Re: most recent output

    On Sat, 11 Sep 2004 06:01:38 -0400, TJM wrote:
    [color=blue]
    >hello,
    >
    >I have a table which contains the audit time field. This audit time field
    >records the current date and time when a record is inserted.
    >I would like to output the most recent top 500 rows.
    >thank you.
    >
    >[/color]

    Hi TJM,

    SELECT TOP 500 Column1, Column2, ..., ColumnN
    FROM ATable
    ORDER BY AuditTimeColumn DESC


    Best, Hugo
    --

    (Remove _NO_ and _SPAM_ to get my e-mail address)

    Comment

    • TJM

      #3
      Re: most recent output

      what if there are other fields in the order by clause?

      So, it is like.. I queried the most recent top 500 rows and then I need to
      sort by column 1, column2, column3 within the most recent top 500 rows.

      is it possible to make them in one query to generate the output?

      thanks again

      "Hugo Kornelis" <hugo@pe_NO_rFa ct.in_SPAM_fo> wrote in message
      news:ld26k0tdcl g85gt4n86ojlfrn vh58qi76c@4ax.c om...[color=blue]
      > On Sat, 11 Sep 2004 06:01:38 -0400, TJM wrote:
      >[color=green]
      > >hello,
      > >
      > >I have a table which contains the audit time field. This audit time field
      > >records the current date and time when a record is inserted.
      > >I would like to output the most recent top 500 rows.
      > >thank you.
      > >
      > >[/color]
      >
      > Hi TJM,
      >
      > SELECT TOP 500 Column1, Column2, ..., ColumnN
      > FROM ATable
      > ORDER BY AuditTimeColumn DESC
      >
      >
      > Best, Hugo
      > --
      >
      > (Remove _NO_ and _SPAM_ to get my e-mail address)[/color]


      Comment

      • Hugo Kornelis

        #4
        Re: most recent output

        On Sun, 12 Sep 2004 21:57:13 -0400, TJM wrote:
        [color=blue]
        >what if there are other fields in the order by clause?
        >
        >So, it is like.. I queried the most recent top 500 rows and then I need to
        >sort by column 1, column2, column3 within the most recent top 500 rows.
        >
        >is it possible to make them in one query to generate the output?
        >
        >thanks again
        >[/color]
        Hi TJM,

        Yes - use a derived table:

        SELECT Column1, Column2, ..., ColumnN
        FROM (SELECT TOP 500 Column1, Column2, ..., ColumnN
        FROM ATable
        ORDER BY AuditTimeColumn DESC) AS DerivedTable
        ORDER BY Column1, Column2, Column3
        (untested)

        Best, Hugo
        --

        (Remove _NO_ and _SPAM_ to get my e-mail address)

        Comment

        Working...