Solved

SQL - Show hospitals Patient most recent visit

Posted on 2014-02-10
5
380 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
[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
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 50

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
default value of combobox 25 70
Email question 19 93
Access VBA Expected end of statement 5 54
ms/access follow hiperlink and generate image 5 16
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

739 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