Solved

SQL - Show hospitals Patient most recent visit

Posted on 2014-02-10
5
375 Views
Last Modified: 2014-02-11
Two tables in Access - One-to-many

tblPatient
-------------
PatientID
PatientName


tblVisits
-----------
PatientID
DateOfVisit

I want a simple SQL that shows all patient names ONCE and also shows their latest tblVisits.DateOfVisit.

What is my SQL syntax?
0
Comment
Question by:Patrick O'Dea
5 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 167 total points
ID: 39847828
test this query

select P.PatientName, Max(V.DateOfVisit)
from tblPatient as P Inner Join tblVisits As V
On P.PatientID=V.PatientID
Group by P.PatientName
0
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 167 total points
ID: 39847834
You should group by the ID, except if you wish to sort on the patient name.

/gustav
0
 
LVL 7

Assisted Solution

by:Steve
Steve earned 166 total points
ID: 39847852
Something along the lines of:
SELECT tblPatient.PatientName, Max(tblVisits.DateOfVisit) AS [Last Visit]
FROM [tblVisits] INNER JOIN tblPatient ON tblVisits.PatientId = tblPatient.PatientId
GROUP BY tblPatient.PatientId;

Open in new window

0
 

Author Closing Comment

by:Patrick O'Dea
ID: 39851223
Thanks all, I got it working.

(On a separate note , a special thanks to sodea63 ... WHY? because I can't help but wonder if we share the same surname.... O'Dea ??)
0
 
LVL 7

Expert Comment

by:Steve
ID: 39851245
Yes we do. Were family somewhere down the tree.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

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