Solved

SQL to retrieve the last receipt an individual was included in.

Posted on 2009-07-14
1
176 Views
Last Modified: 2012-05-07
Hi,
I'm looking at trying to determine, for each member in the system, the last receipt they appeared on. The tables look as follows (in brief):

Receipts: Unqiue ID, Member ID, Receipt Date

Each member can appear multiple times in the table. What I want is, for each member, provide me the unique ID for the last receipt they appeared on based on receipt date.

THanks.
0
Comment
Question by:bryan_z
1 Comment
 
LVL 17

Accepted Solution

by:
pssandhu earned 250 total points
ID: 24851212
Select *
From  Receipts r inner join (Select MemberID, MAX(ReceiptDate) Date From receipts Group by MemberID) m
          ON r.memberID = m.memberid and r.ReceiptDate = m.Date
P.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now