Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW TO MARK THE LAST RECORD IN A GROUP

Status
Not open for further replies.

NEW2003

Technical User
Jul 30, 2003
6
0
0
US
Does anyone know how to mark the last record of a group. ex:
john doe made 3 order, i need to indicate the last record for john doe.

customer order Indicator
john doe 125
john doe 245
john doe 524 1
jane doe 536
jane doe 824 1
 
You could put a date/time attribute with each order, then search for the most current date/time, which would give you the last order placed.
 
Do order numbers always increment within customer as
shown in your example, i.e., will a more recent order
for John Doe always have a higher order number than an
earlier order for John Doe? If so, you could say:

UPDATE tblCustomers
SET tblCustomers.[indicator] = "1"
WHERE tblCustomers.ORDER
In (select max(order) from tblCustomers group by Customer);

If you're setting this indicator so that you can retrieve
the most recent order for each customer, then perhaps you
don't really need the indicator at all. The following
will retrieve the most recent order without using any
indicator. (Same idea as the first query, but this time
as a Select query rather than an Update.):

SELECT tblCustomers.*
FROM tblCustomers
WHERE tblCustomers.ORDER
In (select max(order) from tblcustomers group by customer);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top