
SQL antipatterns
by Bill Karwin · first published 2010
43mentions
31recommended by
37HN commenters
2010–2025first – last mentioned
84% recommend14% neutral3% critical
Why HN recommends it
Easy-to-read tour of common database design and query mistakes. Each chapter shows the naive approach, why it fails, and a better one (EAV, trees, polymorphic associations). Suits those past SQL basics.
Summarised by Claude from recommending comments
Affiliate links. As an Amazon Associate I earn from qualifying purchases.






SQL Antipatterns by Bill Karwin has an chapter that covers this problem in depth. http://shop.oreilly.com/product/mobile/9781934356555.do
on “Hierarchies with Postgres (2013)” ↗I enjoyed SQL Antipatterns by Bill Karwin. Very easy to read and offers some practical approaches to common issues.
on “Our SQL interview questions” ↗…developer. An example is a pretty simple technical concept like dealing with polymorphic associaions in database modeling. There is nothing rocket sciency here, but having read a chapter in Bill Karwin's SQL Antipatterns book, I feel like I have learned a lot. That said, it often happens that you might not encounter certain techniques or approaches for a long time and your knowledge fades. This is why I briefly described…
on “Ask HN: Do you use any kind of journal to improve the efficiency of learning?” ↗I'd do the same. I think this book is still relevant: http://www.amazon.com/SQL-Antipatterns-Programming-Pragmatic...
on “Ask HN: Implementing a graph database using Postgres tables for nodes and edges?” ↗…frameworks encourage antipatterns by design (Bill Karwin's book on the subject [1] is a great, easy read for those who can't stomach C. J. Date's 1000 page "Introduction" [2]). [1] http://www.amazon.com/SQL-Antipatterns-Programming-Pragmatic... [2] http://www.amazon.com/Introduction-Database-Systems-8th/dp/0...
on “Does the Database Community Have an Identity Crisis?” ↗On this topic I'd like to plug a book that really drove this home for me: "SQL Antipatterns" by Bill Karwin.
on “SQL vs. NoSQL Databases: What’s the Difference?” ↗I found SQL Antipatterns by Bill Karwin to be a great book on the topic of patterns and best practices with SQL. As a bonus, it's relatively platform agnostic if I recall correctly.
on “A beginners guide to thinking in SQL” ↗Not online, but SQL Antipatterns is the book that had the largest impact on my thinking: https://www.amazon.com/SQL-Antipatterns-Programming-Pragmati... But as you said, you haven't actively learned SQL, so probably need to find some…
on “Ask HN: What is the best online resource to learn advanced SQL?” ↗…(WITH RECURSIVE was added in 10.2.2 according to the site) and it still needs an explicit alias for SELECT ... FROM (SELECT ...) style constructions. SQLite can't do RIGHT/FULL OUTER JOIN etc. Karwin's SQL Antipatterns is a good book for a "second look at SQL" but I wouldn't really call it advanced yet. The manuals for postgres and MariaDB, while written as manuals and not tutorials, contain a lot of useful information…
on “Bobby Tables” ↗I read SQL Antipatterns[0] - Avoiding the Pitfalls of Database Programming by Bill Karwin a while ago and really liked it. [0] https://pragprog.com/book/bksqla/sql-antipatterns
on “We saved $50k/year with a Go microservice coded in a hackathon” ↗It gets recommended all the time in these kind of threads, but it's so good I don't care. Bill Karwin's SQL Antipatterns. You need a decent understanding of the basics to get the most from it, but there's some excellent information and examples of what to (and what not to) do. https://www.oreilly.com/library/view/sql-antipatterns/978168...
on “Ask HN: Resources for Learning about Databases” ↗Adding to the above, Schönig's Mastering PostgreSQL 11 will help you advance from intermediate to high-intermediate PostgreSQL programmer, as will Faroult's The Art of SQL. Karwin's SQL Antipatterns is useful supplementary reading also. I've looked through my kindle, and I wouldn't bother with much else.
on “PostgreSQL 13” ↗I would suggest picking up Bill Karwin's book on SQL Antipatterns. He goes through a few ideas. I found this slide show from him. It covers the same ideas: https://www.slideshare.net/billkarwin/models-for-hierarchica...
on “The surprisingly difficult problem of user-defined order in SQL” ↗One of my favorite books to throw out for noobs is both a pattern and antipattern book for database folks. https://www.amazon.com/SQL-Antipatterns-Programming-Pragmati...
on “Ask HN: Is DBA still a good job?” ↗…https://www.amazon.com/gp/product/B006L21AO6 - Trees and Hierarchies in SQL for Smarties: https://www.amazon.com/gp/product/B006Y8MKUU - Thinking in Sets: https://www.amazon.com/gp/product/B001AODZZC ------- - SQL Antipatterns by Bill Karwin: https://www.amazon.com/SQL-Antipatterns-Programming-Pragmati...
on “Ask HN: What are some good books for SQL/DBA?” ↗