Practical SQL by journalist and data analyst Anthony DeBarros is a beginner-friendly guide to the database programming language SQL. Starting with SQL basics, you'll work through intermediate and advanced topics including statistics, aggregation, cleaning data, GIS and automating tasks. Along the way, you'll use real-world data from the U.S. Census and other government agencies and learn the fundamentals of good database design. This book is ideal for beginners as well as those who know some SQL and want to go deeper.
Practical SQL uses the free, open-source database PostgreSQL, the pgAdmin GUI, and the PostGIS extension -- technologies used by developers around the world. Much of the SQL syntax and concepts are transferable to other database systems such as MySQL, SQLite, and Microsoft's SQL Server. The book notes when syntax or a function is PostgreSQL-specific.
Practical SQL is published by No Starch Press and available in PDF, .mobi, .epub, and classic print formats.
Questions? I love to hear from readers. Please email [email protected]
Code: All the SQL statements and command-line listings used in each chapter, organized by chapter folders.
Data: CSV files and GIS shapefiles for you to import, also organized by chapter. NOTE! See the warning below about opening CSV files with Excel or text editors in the section on Getting the Code and Data.
Exercises: The "Try It Yourself" questions and answers for each chapter, listed separately. Try working through the questions before peeking at the answers!
FAQ, Updates, and Errata: Answers to frequently asked questions, updates, and corrections are noted at faq-updates-errata.md.
Resources: Updates to the book's Appendix on Additional PostgreSQL Resources at resources.md.
You can obtain all the code and data at once by downloading this repository as a .zip file. To do that:
Warning about CSV files!: Opening CSV files with Excel could lead to data loss. Excel will remove leading zeros from numbers that are intended to be stored as text, such as zip codes. If you wish to view the contents of a CSV file, only do so with a plain-text editor and be careful not to save the file in an encoding other than UTF-8 (e.g.,
Notepad.exe on Windows defaults to ANSI).
GitHub users may want to clone the repository locally and occasionally perform a
git pull to receive any updates.