SQL Style Guide

— by Dat Le on 23th Feb 2017

Consistent SQL style would help a lot in code review and development process, especially when SQL is the main language we use in the data team at honestbee.

Below are all the rules and conventions:


  • All keywords need to be capitalized, it helps with readability, even if no syntax highlighting available.
  • Proper indentation is also important for code readability
  • Table references should always be used when more than one table is referred in a query
  • Avoid using alias unless absolutely necessary, naming should be underscore-separated


  • Always specify which JOIN function to use, either LEFT JOIN, RIGHT JOIN,INNER JOIN, and so on…
  • LEFT JOIN should mainly be used when applicable
  • Starts with the deepest level of data (i.e with the most number of rows)

Sub Queries & Aggregations

  • Common Table Expressions (CTEs) or Temporary Tables should be used instead of Sub Queries
  • Aggregation functions should only be used on columns that are necessary
Like what you read? Give Le Nguyen The Dat a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.