vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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.btinternet.com... > 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 > |
| ||||
| 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.btinternet.com... > 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 > > |