Solved

SQL - Show hospitals Patient most recent visit

Posted on 2014-02-10
5
371 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 119

Accepted Solution

by:
Rey Obrero earned 167 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Yes we do. Were family somewhere down the tree.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

762 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