Write a SQL query to retrieve the top 10 most frequent diagnoses from a patient database at Massachusetts General Hospital.
Use the diagnosis_records table and the diagnosis_codes lookup table. Count recorded diagnosis occurrences, exclude records without a matching diagnosis code, and return fewer than 10 rows if fewer than 10 valid diagnoses exist.
diagnosis_code, diagnosis_name, and diagnosis_count.diagnosis_count descending, then diagnosis_code ascending to break ties.| Column | Type | Description |
|---|---|---|
| record_idPK | INT | Unique diagnosis record identifier |
| patient_id | INT | De-identified patient identifier |
| diagnosis_code | VARCHAR(10) | Recorded diagnosis code |
| diagnosed_on | DATE | Date the diagnosis was recorded |
| Column | Type | Description |
|---|---|---|
| diagnosis_codePK | VARCHAR(10) | Standard diagnosis code |
| diagnosis_name | VARCHAR(150) | Human-readable diagnosis name |