troubleshooting Question

Strategy for a query

Avatar of soozh
soozhFlag for Sweden asked on
Microsoft SQL ServerSQL
5 Comments1 Solution77 ViewsLast Modified:
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?
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros