find min/max date in access which also return their value for each record

5 pts.
Tags:
Microsoft Access
I have a table with more date per record (ID1 thru ID10) and the each date have a score, I want to select from each record of their min date and max date with their score (the score is not the min/max score), the data set is:

ID    Date              Score

1     12/03/2003     90

1     15/06/2003     85

1     10/09/2003     100

2     10/02/2003      85

2      18/03/2003     88

2     30/07/2003     60

3     15/04/2003      75

3     20/05/2003      50

3     30/08/2003      88 ........

I want the result is:

ID   Min Date     Score        Max Date     Score

1    12/03/2003   90          10/09/2003    100

2    10/02/2003   85          30/07/2003    60

3    15/03/2003   75          30/08/2003    88

Thank you.

Regard



Software/Hardware used:
Access 2003
ASKED: May 8, 2010  5:44 PM
UPDATED: May 10, 2010  4:15 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Assuming that a unique index or pk exists on (id,date), a SQL query like this should work (but someone else might want to offer a more efficient way to do it):

<pre>SELECT t1.id, t1.mindate, t2.score, t1.maxdate, t3.score
FROM
(SELECT id, MIN(date) mindate, MAX(date) maxdate
FROM YourTable GROUP BY id) t1
JOIN (SELECT id,date,score FROM YourTable) t2
ON t1.id = t2.id
AND t1.mindate = t2.date
JOIN (SELECT id,date,score FROM YourTable) t3
ON t1.id = t3.id
AND t1.maxdate = t3.date;</pre>

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following