Patients With a Condition - Problem

You are given a table Patients containing information about hospital patients. Each patient has a unique patient_id, a patient_name, and a conditions column that contains medical condition codes separated by spaces.

Your task: Find all patients who have Type I Diabetes. Type I Diabetes codes always start with the prefix DIAB1.

Return the patient_id, patient_name, and conditions for these patients in any order.

Table Schema

Patients
Column Name Type Description
patient_id PK int Primary key, unique identifier for each patient
patient_name varchar Full name of the patient
conditions varchar Medical condition codes separated by spaces (can be empty)
Primary Key: patient_id
Note: The conditions column contains 0 or more condition codes separated by spaces

Input & Output

Example 1 — Mixed Conditions
Input Table:
patient_id patient_name conditions
1 Daniel YFEV COUGH
2 Alice
3 Bob DIAB100 MYOP
4 George ACNE DIAB100
5 Alain DIAB201
Output:
patient_id patient_name conditions
3 Bob DIAB100 MYOP
4 George ACNE DIAB100
5 Alain DIAB201
💡 Note:

Patients Bob, George, and Alain have conditions starting with DIAB1. Bob has DIAB100 at the start, George has DIAB100 after a space, and Alain has DIAB201. Daniel and Alice don't have any Type I Diabetes conditions.

Example 2 — Edge Cases
Input Table:
patient_id patient_name conditions
1 John DIAB1
2 Jane XDIAB100
3 Mike
Output:
patient_id patient_name conditions
1 John DIAB1
💡 Note:

Only John matches because his condition starts with exactly DIAB1. Jane's XDIAB100 doesn't match because DIAB1 is not at the beginning of a word. Mike has no conditions.

Constraints

  • 1 ≤ patient_id ≤ 100000
  • patient_name consists of uppercase and lowercase letters and spaces
  • conditions consists of uppercase letters and spaces, separated by single spaces
  • Type I Diabetes conditions always start with DIAB1 prefix

Visualization

Tap to expand
Finding Patients With Type I DiabetesAll PatientsPatients Table1 | Daniel | YFEV COUGH3 | Bob | DIAB100 MYOP4 | George | ACNE DIAB1005 | Alain | DIAB2012 | Alice | (empty)LIKEFilterDIAB1%Type I Diabetes PatientsFiltered Results3 | Bob | DIAB100 MYOP4 | George | ACNE DIAB1005 | Alain | DIAB201Pattern Matching Logic:conditions LIKE 'DIAB1%' OR conditions LIKE '% DIAB1%'Key InsightCheck for DIAB1 at string start OR after a spaceto match complete word boundaries
Understanding the Visualization
1
Input
Patients table with condition codes
2
Filter
Match DIAB1 prefix patterns
3
Output
Patients with Type I Diabetes
Key Takeaway
🎯 Key Insight: Use LIKE with multiple patterns to match prefixes at word boundaries in space-separated strings
Asked in
Amazon 15 Google 8 Microsoft 12
28.5K Views
Medium Frequency
~8 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen