The patient name on the wristband

The patient name on the wristband

You are a reports developer at a clinic. The patient wristband printer needs a single field with the full name: last name, first name and — when present — the middle name, separated by single spaces. Some patients have no middle name (NULL), and the band must contain no double or trailing spaces: the admissions scanner compares the name character by character. Return columns: - patient_id — patient id (integer); - full_name — a string of the form 'Lastname Firstname Middlename' with a single space as separator; when the middle name is missing it simply does not participate (no stray trailing spaces). Sorting: by full_name ascending, identical names ordered by patient_id ascending. Return all patients.

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables. Your answer must use the same column names as this sample — alias them with AS if needed.

patient_idfull_name
4Bauer Chris
10Costa Bruno Miguel
7Hansen Freja
PostgreSQLv16

Your query result will appear here

Focus radio
Paused · SomaFM · Fluid