Match the Diabetes Prefix at a Space-Delimited Condition Boundary
Company: Microsoft
Role: Software Engineer
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
### Problem
Return patient_id, patient_name and conditions for patients with a condition code beginning DIAB1. Conditions contains zero or more codes separated by spaces. Match a code prefix, not a DIAB1 substring inside an unrelated code. Result order is unrestricted.
### Tables
Table: `Patients`
```text
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| patient_id | int |
| patient_name | varchar |
| conditions | varchar |
+--------------+---------+
patient_id is the primary key (column with unique values) for this table.
'conditions' contains 0 or more code separated by spaces.
This table contains information of the patients in the hospital.
```
### Example
```text
Patients (patient_id,patient_name,conditions): (1,Ada,"COLD DIAB123"), (2,Bo,"XDIAB100"), (3,Cam,"DIAB2"), (4,Dee,"")
Output (patient_id,patient_name,conditions): (1,Ada,"COLD DIAB123")
```
### What a Strong Answer Covers
- Check the prefix at the start of a condition code.
- Keep the requested patient fields and exclude matches that occur inside another code.
### Follow-up Questions
- How would you return the matched condition code alongside the patient fields?
- How would the query change if each condition were stored in its own row?
Overview: Find patients whose list of condition codes includes a code beginning with DIAB1.