Sylvics Apply for the beta
SQL style notes for saved queriesReference
REFERENCE

SQL style notes for saved queries

📌 TL;DR / Quick Summary <div style="background: rgba(0,0,0,0.3); border: 1px dashed rgba(255,255,255,0.2); padding: 15px; border-radius: 8px; color: rgba(255,255,255,0.7); margin-bottom: 30px;"> My own conventions for any query I save. Written on Friday 7 February, the day after Priya's forty minutes at her desk, when I opened Exception list queries and could not read what I had written in January. </div>

🛠️ Instructions / Core Material

  1. Comment first. The top line says, in a sentence, what question this answers and for whom. If I cannot write the sentence I do not have a query yet.
  2. One clause per line. select, from, where, group by, each starting its own line. One column per line when there are more than three.
  3. No clever joins. If a join needs a diagram, it becomes two queries with a name each. I would rather run two things I understand.
  4. Lower case throughout. Shouting keywords helps nobody.
  5. Name what you count. open_exceptions, never cnt or n.
  6. Say the time. Every query that mentions open says open when. 09:00 local is the default and is written out.
  7. One customer, one week while writing. Widen only once the small answer looks right.
  8. Last line of the comment: the date I last ran it and the number it gave, so that next time I know if something has moved.

This is the readable half of ♦️ SQL for product questions. The other half is knowing when to ask Bao.

⚠️ Key Warnings / Constraints

  • A median and an average are different queries. Write the one I mean. Show me Tuesday.
  • Never paste customer names into a saved query. Use the id and look the name up separately.
  • If a result surprises me, the query is wrong more often than the world is. Check row counts before telling anyone.

🔗 Related Entities & Resources

  • Exception list queries: the first queries rewritten to follow these notes
  • ♦️ SQL for product questions: the skill this is the readable half of
  • Priya Raman: whose forty minutes at her desk started it