473,320 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

returning N most recent records, iteratively

I need to perform the following:
- select the most recent X number of records in a table (there is a
timestamp field)
- select the Nth occurrence of X number of records

ex:
- most recent 10 records (N is 1)
- most recent records 10-20 (N would be 2)
- most recent records 10-30 (etc.)

What is the best method to do this?

Apr 25 '07 #1
2 3270
On 25 Apr 2007 13:58:38 -0700, "robert.waters"
<ro***********@gmail.comwrote:

For the 3rd one you probably meant: most recent records 20-30 (etc.)

SELECT TOP 10 *
FROM Orders
ORDER BY OrderDate;

SELECT TOP 10 *
FROM Orders
Where OrderID not in (SELECT TOP 10 OrderID FROM Orders ORDER BY
OrderDate)
ORDER BY OrderDate;

SELECT TOP 10 *
FROM Orders
Where OrderID not in (SELECT TOP 20 OrderID FROM Orders ORDER BY
OrderDate)
ORDER BY OrderDate;

-Tom.

>I need to perform the following:
- select the most recent X number of records in a table (there is a
timestamp field)
- select the Nth occurrence of X number of records

ex:
- most recent 10 records (N is 1)
- most recent records 10-20 (N would be 2)
- most recent records 10-30 (etc.)

What is the best method to do this?
Apr 26 '07 #2
Use a SELECT TOP query (sample below)

I'd be tempted to build the SQL statement in code using a form event.
The results could then be displayed in a datasheet-style subform by setting
the RecordSource of the subform to that manufactured SQL statement.
SELECT TOP 10 tblFldDate.flddate
FROM tblFldDate
WHERE (((Year([flddate]))=2007))
ORDER BY tblFldDate.flddate DESC;

Using the TOP predicate doe not return the highest values, nesecarily ...
without sorting the fldDate in descending sort order
(DESC) I get Jan1, 2, 3 ... With it I get Dec 31, 30, 29 ...

Dates/Times can be tricky to work with as well as they are just
"representations" (formats) of some really odd-looking numbers.
I'd be more inclined to use the SELECT TOP on an AutoNumber field to return
the TOP 'n' records (in the order they were entered) ... if that works for
you.
"robert.waters" <ro***********@gmail.comwrote in message
news:11*********************@r35g2000prh.googlegro ups.com...
>I need to perform the following:
- select the most recent X number of records in a table (there is a
timestamp field)
- select the Nth occurrence of X number of records

ex:
- most recent 10 records (N is 1)
- most recent records 10-20 (N would be 2)
- most recent records 10-30 (etc.)

What is the best method to do this?

Apr 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Nova's Taylor | last post by:
Hi folks, I am a newbie to Python and am hoping that someone can get me started on a log parser that I am trying to write. The log is an ASCII file that contains a process identifier (PID),...
2
by: news | last post by:
Hi there, Looking for a way of returning the Xth to Yth records of an Oracle database I thought using ROWNUM. Here is the solution I came up with. SELECT * FROM ( SELECT ROWNUM RECID, t.*,
1
by: Tim Graichen | last post by:
Good morning, I have a sub-form that displays records from a table as a continuous form. The table has several hundred records, but the subform only displays five or six records. The records do...
2
by: Shaiguy | last post by:
I have a table containing the following fields: ProjectUpdateID (PrimaryKey) ProjectID UpdateDate I would like to create a Query in Ms Access 2000 which will return me the most recent 2...
3
by: manny | last post by:
Problem: how to have query show only most recent records. This query shows all exams in 2005 for particular individual (grades not shown to avoid embarrassing John Slacker!): SELECT...
13
by: Kirk McDonald | last post by:
Say I have a database containing chunks of Python code. I already have a way to easily load, edit, and save them. What is slightly baffling to me is how I can effectively pass this code some...
4
by: Sector 7G | last post by:
I'm working with a SQL query for a Human Resources database. Its intended purpose is to find all the paycheck records with a check date (prckhist.chkdate ) more recent than eleven days past the...
4
by: noddy | last post by:
I have a mysql table called Users The userID field values start at 100 and increment up from there I am trying to transfer values from this table into a javascript array Here is what the code...
13
by: angi35 | last post by:
Hi - working in Access 2000... my goal is to combine fields from two tables in a query: Table 1 has ItemNumber and ItemDescription. There's only one record per ItemNumber. Table 2 has ItemAlias....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.