The Querynomicon

An Introduction to SQL for the Cautious and Weary

Setup

Lessons

  1. Introduction: where we're going and why
  2. Core Features: getting values from tables
  3. Missing Values: handling data that's not there
  4. Aggregating and Grouping: combining data
  5. Combining Information: working with multiple tables
  6. Modifying Data: create, delete, and change
  7. Practice Questions
  8. Keys: primary and foreign
  9. Conditionals: if, else, and variants
  10. Subqueries: and common table expressions
  11. More Comparisons: individual values to aggregates
  12. Tools: Miscellaneous things that make life easier
  13. Practice Questions
  14. Advanced Features: when you need 'em, you need 'em
  15. Conclusion: where we've been and what comes next

2026-01-19: we will also discuss "Data Modelling" and "Ethics", and explore a dataset provided by the learners' organization (which will be shared in class).

Appendices

  1. License
  2. Code of Conduct
  3. Contributing
  4. Bibliography
  5. Glossary
  6. Practice Answers
  7. More Answers
  8. Python: using databases from Python
  9. R: using databases from R
  10. PostgreSQL: client-server computing and permissions

Acknowledgments

This tutorial would not have been possible without:

We also thank the following people for spotting issues, making suggestions, or submitting changes:

  • Yanina Bellini Saibene
  • Phillip Cloud
  • Zoe Daniels
  • Conor Flynn
  • Andy Goldberg
  • Jay Graves
  • Sam Hames
  • Adam Hawkes
  • Robert Kern
  • Olivier Leroy
  • Kevin Marshall
  • Roy Pardee
  • Manos Pitsidianakis
  • Daniel Possenriede
  • Adam Rosien
  • Thomas Sandmann
  • Simon Willison

start where you are · use what you have · help who you can