1. [Home](<https://delaparra-services.nl/>) 
1. [Knowledge hub](<https://delaparra-services.nl/knowledge-hub>) 
1. [CASE](<https://delaparra-services.nl/knowledge-hub/case>)

  

Category: SQL 

# CASE

  Explained by [Reinier de la Parra](<https://delaparra-services.nl/about>)  Updated November 25, 2026    

## What is CASE?

 

CASE: SQL’s if/else expression — return different values per row based on conditions. Handy for bucketing and pivoting. ` CASE ` is SQL's if-else expression. It returns a different value per row depending on conditions, such as ` CASE WHEN total > 1000 THEN 'large' ELSE 'small' END `. It is useful for grouping values into buckets, translating codes into readable labels, or counting several categories in one query. ` SUM(CASE WHEN status = 'paid' THEN 1 ELSE 0 END) ` counts paid orders while you also count other statuses in the same result.

 

Definition source [Coders Lingo](<https://coderslingo.com/resources/open-dataset/>), [CC BY 4.0](<https://creativecommons.org/licenses/by/4.0/>)

 

## Frequently asked questions about CASE

  

### What should you keep in mind with CASE?

 

Conditions are checked from top to bottom, and the first match wins, so put the most specific ones first. Without an ` ELSE `, unmatched rows get ` NULL `, which can surprise you later. If the same ` CASE ` logic appears in many queries, consider storing the result in a column or a lookup table, so the rule lives in one place.

    

### What does an example of CASE look like?

 

```
SELECT name, CASE WHEN age < 18 THEN 'minor' WHEN age < 65 THEN 'adult' ELSE 'senior' END AS bracket FROM people;
```

 

## At a glance

   CategorySQL Explained by[Reinier de la Parra](<https://delaparra-services.nl/about>) UpdatedNovember 25, 2026

 

## More SQL terms

 

- [ACID](<https://delaparra-services.nl/knowledge-hub/acid>) 
- [B-tree index](<https://delaparra-services.nl/knowledge-hub/b-tree-index>) 
- [BEGIN / COMMIT / ROLLBACK](<https://delaparra-services.nl/knowledge-hub/begin-commit-rollback>) 
- [COALESCE](<https://delaparra-services.nl/knowledge-hub/coalesce>) 
- [composite index](<https://delaparra-services.nl/knowledge-hub/composite-index>) 
- [COUNT / SUM / AVG / MIN / MAX](<https://delaparra-services.nl/knowledge-hub/count-sum-avg-min-max>)

 

[All terms starting with C](<https://delaparra-services.nl/knowledge-hub#letter-c>)

 

## Skills

 

- ### SQL Performance Optimization Assistant

 

'Universal SQL performance optimization assistant for comprehensive query tuning, indexing strategies, and database performance analysis across all SQL databases (MySQL, PostgreSQL, SQL Server, Oracle). Provides execution plan analysis, pagination optimization, batch operations, and performance monitoring guidance.'

 [View skill](<https://delaparra-services.nl/skills/sql-optimization>) [Download zip](<https://delaparra-services.nl/skills/sql-optimization/download>) 
- ### SQL Code Review

 

'Universal SQL code review assistant that performs comprehensive security, maintainability, and code quality analysis across all SQL databases (MySQL, PostgreSQL, SQL Server, Oracle). Focuses on SQL injection prevention, access control, code standards, and anti-pattern detection. Complements SQL optimization prompt for complete development coverage.'

 [View skill](<https://delaparra-services.nl/skills/sql-code-review>) [Download zip](<https://delaparra-services.nl/skills/sql-code-review/download>) 
- ### Laravel Database Optimization

 

Laravel database optimization patterns. Use when writing Eloquent queries, creating migrations, configuring caching, debugging slow queries, or optimizing database performance. Triggers on tasks involving N+1 queries, indexing, Redis caching, pagination, or database transactions.

 [View skill](<https://delaparra-services.nl/skills/laravel-database-optimization>) [Download zip](<https://delaparra-services.nl/skills/laravel-database-optimization/download>)

 [Download all skills (zip)](<https://delaparra-services.nl/knowledge-hub/case/skills.zip>)

 

## Manuals

 

- [Writing SQL queries and migrations](<https://delaparra-services.nl/manuals/sql-queries-en-migraties>) 
- [PHP and Composer](<https://delaparra-services.nl/manuals/php-en-composer>)

 

## Related services

 

- [Custom software and web applications](<https://delaparra-services.nl/services#service-03>)

Perhaps your customers need somewhere to download their invoices, or your staff are managing bookings in a spreadsheet. 
- [AI code review](<https://delaparra-services.nl/services#service-05>)

When you push your new change, I will review your code, help your agent avoid the same mistake again, and get your app ready for deployment.

 

## Need any help?

 

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.

  [Get in touch](<https://delaparra-services.nl/availability>)

[HTML version](https://delaparra-services.nl/knowledge-hub/case)
