ms access query help

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

    ms access query help

    I have a table that has numerical ID.

    I want a query that will get the 20 highest IDs. So in other words the
    query would return the last 20 results entered.

    What would even be better is if they were distinct entries by another
    column, but it still returned 20 results.

    Can you specify in SQL how many results you want?

    Thanks
    Dave

  • Oscar Santiesteban Jr.

    #2
    Re: ms access query help

    You can try the follwing, this is Transact SQL, don't know if it will work
    in MS Access.

    Select top 20 from yourtable
    order by invoice_no desc

    This will get you the highest invoice numbers
    Hope this is what you want.

    Oscar...

    "SkunkDave" <dave_casserly@ totalise.co.uk> wrote in message
    news:bfhkd4$gc4 $1@hercules.bti nternet.com...[color=blue]
    > I have a table that has numerical ID.
    >
    > I want a query that will get the 20 highest IDs. So in other words the
    > query would return the last 20 results entered.
    >
    > What would even be better is if they were distinct entries by another
    > column, but it still returned 20 results.
    >
    > Can you specify in SQL how many results you want?
    >
    > Thanks
    > Dave
    >[/color]


    Comment

    • WKC

      #3
      Re: ms access query help

      Well Dave, It's actually quite simple. All you would have to do is this:

      select top 20 * from [the table name] order by [the ID column] desc

      The reason you want to order by DESC b/c it list the column from the highest
      numbers to the lowest. So, you'll get the top 20 highest records.

      Wei

      "SkunkDave" <dave_casserly@ totalise.co.uk> wrote in message
      news:bfhkd4$gc4 $1@hercules.bti nternet.com...[color=blue]
      > I have a table that has numerical ID.
      >
      > I want a query that will get the 20 highest IDs. So in other words the
      > query would return the last 20 results entered.
      >
      > What would even be better is if they were distinct entries by another
      > column, but it still returned 20 results.
      >
      > Can you specify in SQL how many results you want?
      >
      > Thanks
      > Dave
      >
      >[/color]


      Comment

      Working...