Solved

extract records with the smallest value per group

Posted on 2014-04-17
2
272 Views
Last Modified: 2014-04-18
I have a table containing the following

  Acct #       Collection Date/Time       Result Date/Time       Clinical Event
000005        1/1/2014 00:10:00           1/1/2014 00:42:00     Troponin-T
000005        1/1/2014 00:15:00           1/1/2014 00:20:00     Troponin-I
000005        1/1/2014 01:30:00           1/1/2014 02:10:00     Troponin-T
001002        1/3/2014 23:59:00           1/4/2014 00:45:00     Troponin-T
001002        1/4/2014 05:20:00           1/4/2014 05:25:00     Troponin-I

I need a query that would pull the entire record with the earliest result time for each account.  

For Acct # 0005, I need the record with result date/time of 1/1/2014 00:20:00 (2nd rec)
For Acct # 1002, I need the record with result date/time of 1/4/2014 00:45:00 (4th rec)
0
Comment
Question by:ddschreck01
2 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 40007874
test this query


 Select A.*
 From Tablex as A
 Inner join
 (Select min(B.[Result Date/Time]) as MinResult, B.[Acct #]
  from TableX as B
  Group by B.[Acct #]
  ) As C
  On A.[Acct #]= C.[Acct #] And A.[Result Date/Time]=C.[MinResult]
0
 

Author Closing Comment

by:ddschreck01
ID: 40008766
Thank you very much - that worked perfectly.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

895 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