Your question is UNION Two Tables and Deduplicate. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Novo Nordisk's analytics team is consolidating patient records from Wegovy and Ozempic clinical programs. Write a PostgreSQL query that combines both patient tables and removes duplicate records.
patient_id, patient_name, birth_date, and indication from both tables.UNION so identical rows are returned only once. Do not treat records with the same patient_id but different attributes as duplicates.patient_id, then indication.| Column | Type | Description |
|---|---|---|
| patient_id | INTEGER | Patient identifier |
| patient_name | VARCHAR(100) | Patient name |
| birth_date | DATE | Patient date of birth |
| indication | VARCHAR(80) | Clinical indication |
| Column | Type | Description |
|---|---|---|
| patient_id | INTEGER | Patient identifier |
| patient_name | VARCHAR(100) | Patient name |
| birth_date | DATE | Patient date of birth |
| indication | VARCHAR(80) | Clinical indication |