We help IT Professionals succeed at work.
Get Started

Strategy for a query

Last Modified: 2020-01-29
I would like a little help in forming a strategy and query to solve a problem i have.

I have a table called Patients that contains a list of patients.  (One row per patient)

There are three other tables called Population, Incidents and Surgery.  These three tables have a foreign key realtionship with the Patients table.

A patient does not have to have a row in any of the three tables, but can also have multiple rows.  Each row in these tables has a Registration Date which combined with the patient foreign key makes the row unique.

I need to create view over the three tables that shows the Patient and his/her LAST entry in each table.

What would be the best strategy for creating this view?  Should i create CTEs for each table that return the latest row for each patient.  An then join the CTEs with the Patients table? Is there a better way?
Watch Question
Senior DBA
Most Valuable Expert 2018
Distinguished Expert 2019
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE