473,320 Members | 2,133 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.

Finding records containing a maximum


I have a table called Services which contains, among other fields, the
following:
ServiceID
AccountID
ServiceDate

There may be many service records for each account. I wish to select
for
each account the most recent service record.

I can write:
Select AccountID, Max(ServiceDate) As MaxOfServiceDate From Services
Group By AccountID

This gives me the most recent ServiceDate for each account BUT how do
I write some SQL which will also give me the ServiceIDs which have these
service dates?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
1 1826
> I have a table called Services which contains, among other fields, the
following:
ServiceID
AccountID
ServiceDate There may be many service records for each account. I wish to select
for
each account the most recent service record. I can write:
Select AccountID, Max(ServiceDate) As MaxOfServiceDate From Services
Group By AccountID This gives me the most recent ServiceDate for each account BUT how do
I write some SQL which will also give me the ServiceIDs which have these
service dates?


SELECT AccountID, ServiceID, ServiceDate
FROM Services
WHERE ServiceDate=(SELECT Max(S2.ServiceDate)
FROM Services AS S2 WHERE S2.AccountID=Services.AccountID);

(not tested)

HTH - Peter

--
No mails please.
This posting is provided AS IS with no warranties, and confers no rights.
Nov 12 '05 #2

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

Similar topics

11
by: jsfromynr | last post by:
Hi all, Here is the table and DML statments CREATE TABLE ( , NULL , DEFAULT (1), -- 1 Pending ,2 Approved (20) )
2
by: Roger Withnell | last post by:
How do I find the maximum value of a recordset column? I'd rather do it this way than open a new recordset with Max(column). Thanks in anticipation. Posted Via Usenet.com Premium Usenet...
4
by: Bayou BoB | last post by:
Hello; Simple question for most I'm sure. I'm curious how many records MS Access will store in a single database? What happens when you reach that number of records? Do you just lose the ability...
10
by: Thelma Lubkin | last post by:
My form/subform combination that allows user to display 'ColorSet' records, move to other records via a selector, to add,delete, and edit them, and to manage the related 'Color' records from the...
5
by: WilliamRLinden | last post by:
Hi world! we are pretty new to JavaScript and have been struggling for now 2 days on this problem ... We would appreciate mercy if anyone can give us some. Basically we are trying to simulate...
5
by: JSParker1 | last post by:
Summary: Maximum number of records per second that can be inserted into SQLServer 2000. I am trying to insert hundreds (preferably even thousands) of records per second in to SQLServer table...
2
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. ...
3
by: mark4asp | last post by:
Stack of limited size containing unique items? Hi guys, How would I implement a stack of limited size containing unique items? For example. Suppose my stack has . I add 2 to it and it is now...
3
by: bmyers404 | last post by:
I need to update values in a table for a subset of rows returned from a select statement. The select statement may return any number of records. I'll use 15 in this example. I want to update the...
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.