473,411 Members | 2,068 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,411 software developers and data experts.

Max Date Query

I have a problem I'm trying to solve, but for the life of me, cannot figure out how to get it to work.

I have two tables, each with a "Last Update Date" field. The query I want to create would match each "Last Update Date" field for table one, with the most recent date prior to that from table two.

For example. Table one would have records for 5/1/07, I would want the most recent date prior to that from table two (which aren't necessarily the day before).

I've used the "max" function, but can't get more than one date to display. I would need the prior date for every record in table one.

Thanks.
May 1 '07 #1
7 3251
Rabbit
12,516 Expert Mod 8TB
Just set the criteria for the date in Table 2 to < Table1's Date.
May 1 '07 #2
Just set the criteria for the date in Table 2 to < Table1's Date.
That pulls in ALL the dates prior to the table 1 date. I only want the one date that's immediately prior to it.

Sorry if I didn't make that clear.
May 1 '07 #3
Rabbit
12,516 Expert Mod 8TB
Then SELECT TOP 1 and order it by descending date.
May 1 '07 #4
Then SELECT TOP 1 and order it by descending date.
That only gives me the date for one record. I needs the immediately prior date for EACH record from table one. Let me give you an example of the dataset:

table1 table2
5/1/07 5/1/07
5/1/07 4/30/07
5/1/07 4/15/07
5/1/07 4/14/07
4/30/07 4/30/07
4/30/07 4/26/07
4/30/07 4/24/07
4/26/07 4/26/07
4/26/07 4/19/07
4/26/07 4/16/07

So the records I would want returned would be
5/1/07 4/30/07
4/30/07 4/26/07
4/26/07 4/19/07

Does that help?
May 1 '07 #5
Rabbit
12,516 Expert Mod 8TB
Now you're getting into complicated territory. You're going to have to SELECT DISTINCT and use a subquery or DMax to achieve what you want.
May 1 '07 #6
Now you're getting into complicated territory. You're going to have to SELECT DISTINCT and use a subquery or DMax to achieve what you want.
Yep. Already figured out how complicated this is turning out to be. :)
May 1 '07 #7
Rabbit
12,516 Expert Mod 8TB
Yep. Already figured out how complicated this is turning out to be. :)
Let us know if you get stuck on any part of that. First you have to decide if you want to go the DMax route or the subquery route.

DMax is easier but not as efficient.
May 1 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Russell | last post by:
I'm having a fit with a query for a range of dates. The dates are being returned from a view. The table/field that they are being selected from stores them as varchar and that same field also...
2
by: BlackFireNova | last post by:
I have an Access 2003 mdb which contains software records. I need to sort on a particular type of software, and then identify and count how many copies there are per each group of that type...
10
by: Kenneth | last post by:
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in this Query I only want the salesdata for...
7
by: Nicolae Fieraru | last post by:
Hi All, I have a table tblProducts where I have four fields:\ Index, ProductName, EnterDate (as Date/Time - Medium Date), PurchaseDate (Date/Time - Medium Date) The EnterDate is automatically...
4
by: Peter Bailey | last post by:
I have a vba string taht dynamically creates the query which has two dates in it that it grabs off an open form as a string from the textbox. What I generate in vba is: SELECT DOSMBK.Date,...
12
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date...
3
by: manning_news | last post by:
Using A2K. I've been asked to modify a report currently requiring only one date parameter to now accept a date range. The main report has 2 subreports and is not bound to a table or query. The...
11
by: Dixie | last post by:
How can I programatically, take some Date/Time fields present in a table in the current database and change their type to text? dixie
10
by: Daniel | last post by:
In Microsoft Access I can write a query that includes the criteria: Between Date()-7 And Date() to retrieve the records from a table that fall within the last week. I'm trying to write a...
2
by: sixdeuce62 | last post by:
Hello, I am trying to create a query that will prompt me to enter the parameter value if beginning date and ending date. I have created everything I need in the query, but I have to manually go...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.