Sharing my SQL Style Guide

Hey all - I put together a style guide outlining the preferences I’ve adopted over the years for how to format SQL queries. I shared it in dbt Slack and Claire recommended I share here as well.

You can check it out on GitHub here: Mazur’s SQL Style Guide.

Feedback welcome on any of it, especially parts where you’ve adopted different conventions. Cheers!


Very nice style guide. Since you asked for feedback, I’ll share mine.

I prefer “<>” over “!=” for not equals since the former is ANSI SQL-92 and latter is not. It is also very easy to type.

I “group by numbers” all the time. I find it very convenient and I have not heard a good reason (yet) as to why I should not do this. :slight_smile: I always follow “Grouping columns should go first” which I think makes this approach ok.

What is the reasoning for " Commas should be at the the end of lines"? I think there are pros/cons for either approach on this one; I used to put commas at the beginning, but lately have been putting them at the end.

For anything noted as “bad”, it may be good to explain why. Some were obvious to me, some were not.

Thanks for sharing! Nice work.

Hey @davemasino, thanks so much for this thoughtful feedback.

Regarding <> vs !=, I didn’t realize the former was a ANSI SQL-92 standard. TIL. I probably won’t update change the guide it simply because I don’t think it really matters one way or the other, and I just prefer <> is all.

I hear you on grouping by numbers too. I go back and forth on it, as the commit history of the guide would show for anyone who ever checks it out :). Might wind up going back to “numbers are fine” in time, we shall see.

Regarding commas at the beginning, it just looks bad to me. Obviously that’s just a personal preference though. The main argument for having them at the beginning is that it makes diffs cleaner, but that’s doesn’t outweigh the ugliness of it IMO.

Copy on elaborating on the “bad” conventions when I have more than just a personal preference for it.

If you think of anything else that would be worth adding or changing I’d love to chat about it more.



You are welcome, @mhmazur ! Will do for sure.