SQL Boy
TutorialsPlayground

Format & Validate

SQL FormatterSQL MinifierSyntax Validator

Convert

JSON to SQLCSV to SQLSQL to JSONRegex to SQLExcel to SQLSQL Dialect Convertersoon

Visualize

ER Diagram GeneratorSQL Schema Diff

Generate

SQL Mock Data Generator

Analyze

SQL Query ExplainerSQL Query Analyzer

Workflow hubs

FormattingConversionSchemaAnalysis
View all tools
Daily ChallengeInterviewsCheat SheetBlog

© 2026 SQL Boy. Built for developers.

ContactPrivacyTermsAI Usage PolicyEditorial StandardsAboutRSS Feed

New conversation

What can I help with?

Ask about this page, get a hint on a challenge, or explore SQL concepts.

I know what's on this page and can give answers grounded in SQL Boy content.

Current page

Patients With Condition

/challenges/patients-with-condition

Usage status will load after login
SQL Boy
TutorialsPlayground

Format & Validate

SQL FormatterSQL MinifierSyntax Validator

Convert

JSON to SQLCSV to SQLSQL to JSONRegex to SQLExcel to SQLSQL Dialect Convertersoon

Visualize

ER Diagram GeneratorSQL Schema Diff

Generate

SQL Mock Data Generator

Analyze

SQL Query ExplainerSQL Query Analyzer

Workflow hubs

FormattingConversionSchemaAnalysis
View all tools
Daily ChallengeInterviewsCheat SheetBlog
SQL Challenges/Patients With Condition
Challenge DetailEasyReviewed 2026-04-20

Patients With Condition

Find patients who have Type I Diabetes. Condition codes start with 'DIAB1'. Return patient_id and name.

String Functions

This challenge now meets the current minimum standard for sitemap inclusion and independent indexing.

2025-12-19Easy

Patients With Condition

Find patients who have Type I Diabetes. Condition codes start with 'DIAB1'. Return patient_id and name.

Available Tables:
SQL Editor
Loading...

What This Challenge Is Testing

String filtering problems like this come up constantly in healthcare, compliance, CRM tagging, and messy operational systems where multiple codes are packed into one text field. The real skill is writing pattern logic that matches the intended token without accidentally matching nearby strings.

Topic Tags

Sql PracticeData Cleaning

Schema At A Glance

patients
patient_idnameconditions

Solution Approaches

01

LIKE for start-of-string or space-delimited match

SELECT
  patient_id,
  name
FROM patients
WHERE conditions LIKE 'DIAB1%'
   OR conditions LIKE '% DIAB1%'

This solution works because valid matches appear either at the start of the string or immediately after a space. It is compact and fits the simplified schema in this challenge.

02

Pad the string to make token boundaries explicit

SELECT
  patient_id,
  name
FROM patients
WHERE ' ' || conditions || ' ' LIKE '% DIAB1%'

Padding the value with spaces normalizes the matching rule into one pattern. This reduces the chance of forgetting to handle the start-of-string case separately.

Common Pitfalls

The main bug is using `LIKE '%DIAB1%'`, which would also match codes such as `XDIAB100` if token boundaries were not respected. Another issue is forgetting that the condition code may appear at the very beginning of the string, not only in the middle.

Frequently Asked Questions

Why is token boundary handling important here?

Because the problem is not just substring matching. You want a condition code that starts with `DIAB1` as its own code token, not any arbitrary string fragment buried inside another value.

What broader lesson does this challenge teach?

It teaches defensive string filtering on denormalized fields. In real datasets, codes are often packed into one column, so matching logic needs to account for separators and false positives.

Concept Guides

Use these guides when you want the fuller explanation behind the SQL pattern this challenge is testing.

Essential SQL String Functions for Data Cleaning and Analysis

Clean, format, and extract data like a pro. Master essential SQL string functions including UPPER, LOWER, TRIM, REPLACE, SUBSTR, and concatenation.

Data Cleaning with SQL: From Messy to Masterpiece

Real-world data is dirty. Master 4 essential SQL functions to clean strings, handle NULLs, and fix formatting errors.

SQL CASE Statements: Adding Logic to Your Queries

Learn how to add conditional logic to your SQL queries using CASE statements. Transform data and categorize results with ease.

Topic Hubs

If this problem exposed a deeper weakness, use a topic hub to move through a curated cluster instead of random article hopping.

Data Prep

Data cleaning, staging, and SQL-ready inputs

Use this path when the hard part is turning messy files, semi-structured payloads, or staging tables into something you can query with confidence.

Advanced SQL

Advanced query patterns

Use this path when you are moving beyond beginner SELECT queries into CTEs, window functions, and conditional logic.

Practice Path

If you want the rotating practice flow, open this same question from the daily stream. If you want interview-style packaging, continue into the interview pool after this rep.

Back to ChallengesOpen In DailyBrowse Interviews

Related Challenges

Capital Gain/LossMedium

Calculate per-stock capital gain or loss by treating buys as cash outflows and sells as cash inflows before summing them.

Monthly Transactions IMedium

Roll monthly transaction reporting into one query while splitting total volume from approved volume by country.

Products Never OrderedMedium

Find products that never appear in the order table without being fooled by missing or duplicate order rows.

© 2026 SQL Boy. Built for developers.

ContactPrivacyTermsAI Usage PolicyEditorial StandardsAboutRSS Feed