473,396 Members | 1,945 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,396 software developers and data experts.

Returning only min and max dates in Access query

Here's a sample recordset in the table I'm looking at:

Code Subcode Date
10051 26 11/1/2006
10051 26 11/25/2006
10051 26 12/2/2006
10052 10/5/2006
10052 11/7/2006
10052 12/1/2006

I want to write a query that will only return rows with the minimum and maximum date for each code/subcode combination. Using the recordset above, the results of this query would look like this:

Code Subcode Date
10051 26 11/1/2006
10051 26 12/2/2006
10052 10/5/2006
10052 12/1/2006

Any advice would be much appreciated. Thanks!
Dec 11 '06 #1
2 14421
MMcCarthy
14,534 Expert Mod 8TB
Using a union query would return the format you've suggested.

Expand|Select|Wrap|Line Numbers
  1. SELECT Code, Subcode, Max([Date]) As [Date]
  2. FROM TableName
  3. UNION
  4. SELECT Code, Subcode, Min([Date]) As [Date]
  5. FROM TableName
  6. GROUP BY Code, Subcode;
  7.  
Alternatively, you could return two separate date fields as follows:

Expand|Select|Wrap|Line Numbers
  1. SELECT Code, Subcode, Min([Date]) As MinDate, Max([Date]) As MaxDate
  2. FROM TableName
  3. GROUP BY Code, Subcode;
  4.  

Mary
Dec 11 '06 #2
NeoPa
32,556 Expert Mod 16PB
You may want to add :
Expand|Select|Wrap|Line Numbers
  1. ORDER BY Code, Subcode, [Date]
to first version or :
Expand|Select|Wrap|Line Numbers
  1. ORDER BY Code, Subcode
to the second if the order is important. Must be before the ';' though.
Dec 12 '06 #3

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

Similar topics

2
by: Deano | last post by:
OK, I've been taking the detour from hell trying to sort this and after taking a walk I think I need a rethink. I have a report for a single employee that includes a subreport which lists...
5
by: Mal | last post by:
Hello. I have a database that tracks reservations at a campground. I want to be able to make a calendar type report that shows how many people are here in given period. Stored for each...
1
by: Don Sealer | last post by:
I have a report that includes 5 different subreports. I'd like to be able to open this report using a date function (Start Date and End Date). I'd like all five subreports to show the data from...
6
by: Bill R via AccessMonster.com | last post by:
I have a query: SELECT tblCalendar.CalendarDay AS LastSunday FROM tblCalendar WHERE (((tblCalendar.CalendarDay)>=(Now()-7) And (tblCalendar.CalendarDay)...
18
by: PC Datasheet | last post by:
An Access user saw my name in a newsgroup and sent me a request for help on a project. As part of the project, a list of the dates in a month was needed. For anyone needing a list of dates in a...
12
by: Dixie | last post by:
I am trying to calculate the number of workdays between two dates with regards to holidays as well. I have used Arvin Meyer's code on the Access Web, but as I am in Australia and my date format is...
6
by: SQL Server | last post by:
I've been working this for a while. Kind of new to SQL Server functions and not seeing what I am doing wrong. I have this function CREATE FUNCTION dbo.test (@Group varchar(50)) RETURNS...
1
by: pitfour.ferguson | last post by:
My dbase has the start date and end date of each visit. How can I ask Access to list the day of the week of the start (easy), end (easy) and, more importantly, the dates of the visit itself - ie...
13
newnewbie
by: newnewbie | last post by:
I have an Access database that I upload a data extract intoto daily. I want to create a query that will give me a list of dates that no data can be found for. E.g. there are no records created on the...
5
by: jennwilson | last post by:
Using Access 2000 - I have a query that is suppose to return the records from table within specified time range and find matching data from another table . Table houses Clinician name, location...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.