Skip to main content
All Problems
hard0% acceptance

Latest Visit per Patient Using ROW_NUMBER

For each patient, find their most recent visit. Use ROW_NUMBER() to rank visits by date descending within each patient, then filter to only the latest. Return patient_id, first_name, last_name, visit_date, and diagnosis.

Schema

🔑idINT
first_nameTEXT
last_nameTEXT
date_of_birthTEXT
genderTEXT
emailTEXT
phoneTEXTNULL
blood_typeTEXT
cityTEXT
stateTEXT
🔗insurance_idINTNULL
created_atTIMESTAMP
postgresql

Run your query to see results

Press Ctrl + Enter to execute