Solved

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

Posted on 2009-07-14
1
175 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

744 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

12 Experts available now in Live!

Get 1:1 Help Now