The Querynomicon
An Introduction to SQL for the Cautious and Weary
Upon first encountering SQL after two decades of Fortran, C, Java, and Python, I thought I had stumbled into hell. I quickly realized that was optimistic: after all, hell has rules.
I have since realized that SQL does too, and that they are no more confusing or contradictory than those of most other programming languages. They only appear so because it draws on a tradition unfamiliar to those of us raised with derivatives of C. To quote Terry Pratchett, it is not mad, just differently sane.
Welcome, then, to a world in which the strange will become familiar, and the familiar, strange. Welcome, thrice welcome, to SQL.
-
Please see the website to view the current version of this tutorial.
-
Contributions are very welcome: please see the contributors' guide for background and these issues for items where assistance would be most appreciated. Please also see our license for terms of use, and note that all contributors are required to abide by our Code of Conduct.
This lesson notes and working examples for instructors to use as a starting point. We do not expect novices with no prior SQL experience to be able to learn from this on their own. As a musical analogy, these notes are the chord changes and melody; we expect instructors to create an arrangement and/or improvise over the material when delivering it. Please see Teaching Tech Together for background.
Start where you are
Use what you have
Help who you can
Syllabus
- Introduction: where we're going and why
- Core Features: getting values from tables
- Tools: Miscellaneous things that make life easier
- Advanced Features: when you need 'em, you need 'em
- Python: using databases from Python
- R: using databases from R
- PostgreSQL: client-server computing and permissions
- Conclusion: where we've been and what comes next