Chapter 1: Creating Your First Database and Table
Chapter 2: Beginning Data Exploration with SELECT
Chapter 3: Understanding Data Types
Chapter 4: Importing and Exporting Data
Chapter 5: Basic Math and Stats with SQL
Chapter 6: Table Joins in a Relational Database
Chapter 7: Table Design that Works for You
Chapter 8: Extracting Information by Grouping and Summarizing
Chapter 9: Inspecting and Modifying Data
Chapter 10: Statistical Functions in SQL
Chapter 11: Working with Dates and Times
Chapter 12: Advanced Query Techniques
Chapter 13: Extracting Data from Text
Chapter 14: Analyzing Spatial Data with PostGIS
Chapter 15: Saving Time with Views, Functions, and Triggers
Chapter 16: Using PostgreSQL from the Command Line
Chapter 17: Maintaining Your Database
Chapter 18: Identifying and Telling the Story Behind Your Data
Appendix: Additional PostgreSQL Resources
- Download Chapter 1: Creating Your First Database and Table
- Download the code from GitHub
- Questions about the book or its subject matter? Visit https://practicalsqlbook.com/.
Practical SQL is an approachable and fast-paced guide to SQL (Structured Query Language), the standard programming language for defining, organizing, and exploring data in relational databases. The book focuses on using SQL to find the story your data tells, with the popular open-source database PostgreSQL and the pgAdmin interface as its primary tools.
You’ll first cover the fundamentals of databases and the SQL language, then build skills by analyzing data from the U.S. Census and other federal and state government agencies. With exercises and real-world examples in each chapter, this book will teach even those who have never programmed before all the tools necessary to build powerful databases and access information quickly and efficiently.
You’ll learn how to:
- Create databases and related tables using your own data
- Define the right data types for your information
- Aggregate, sort, and filter data to find patterns
- Use basic math and advanced statistical functions
- Identify errors in data and clean them up
- Import and export data using delimited text files
- Write queries for geographic information systems (GIS)
- Create advanced queries and automate tasks
Learning SQL doesn’t have to be dry and complicated. Practical SQL delivers clear examples with an easy-to-follow approach to teach you the tools you need to build and manage your own databases.
This book uses PostgreSQL, but the SQL syntax is applicable to many database applications, including Microsoft SQL Server and MySQL.
“One of the best-organized travelogues we've seen into the SQL realm.”
Figure 1 on page xxxiii of the Introduction shows the pgAdmin app's opening screen. Beginning with version 3.0 of pgAdmin, released in April 2018, the application loads as a tab within your default web browser. Previous versions of pgAdmin run as a standalone desktop application. All other functionality for pgAdmin described in the book remains the same.
In step 6, change "In the SQL Editor pane ..." to "In the Query Editor pane ..."
The results shown for Listing 12-3 are correct. However, the first sentence after the results has an incorrect number. It should read, "The difference between the median and average, 72,376, is nearly three times the size of the median."
Change "When you hover your cursor over any cell ..." to "When you double-click on any cell ..."
The final line in Listing 13-13 should have a space instead of a comma between the quote marks in the second argument. It should read:
SELECT regexp_split_to_array('Phil Mike Tony Steve', ' ');
The final line of Listing 13-25 is missing a semi-colon. It should read: