?
Solved

extract records with the smallest value per group

Posted on 2014-04-17
2
Medium Priority
?
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

770 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