How to map table rows to columns using SQL PIVOT or CASE expressions

Introduction

I’m now reading the wonderful SQL Antipatterns book by Bill Karwin. The book is a great reference for any developer that needs to interact with a Relational Database System.

In this book, the Entity-Attribute-Value (EAV) model is portrayed as an Anti-Pattern. Although I must admit that a proper relational schema is almost always the best approach when designing an enterprise system, there are use cases when the EAV model is justified.

In this post, I’m going to explain when to use EAV and how to transpose a ResultSet so that rows become columns.

Continue reading “How to map table rows to columns using SQL PIVOT or CASE expressions”

Advertisements