So today while doing some SQL tutorials as a refresher, I ran into the `HAVING` keyword, and my mind was a little bit blown.

Like... I *must* have known about this at some point? I did a databases course during my computer science degree.

But somehow the entire concept had fallen out of my head, and I have spent years using CTEs or subqueries to get around this fundamental gap in my knowledge.

Whoops.

Follow

@msuriar

A contrary opinion: it's terrible. You can do whatever you can do with it with subqueries, any reasonable optimizer will treat both identically, and HAVING makes things appear less composable than they are (tbf group by by itself already has that property, but knowing about HAVING but not about subqueries makes one assume that SQL is noncomposable).

@robryk @msuriar But for quick and dirty situations, where you want to make a minimal modification to an already-existent query (especially if it's on a large dataset and queries take minutes, and the query was written by Wise Old Ones e.g. yourself several months ago), it looks like it could be a lifesaver. I too am pretty sure I knew this and that it just fell out the side of my brain.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.