Cover of SQL Queries for Mere Mortals by John Viescas β€” a beginner-friendly guide to writing SQL queries against relational databases

Pages

670

SQL ✨ New

Sql Queries For Mere Mortals

A Hands-On Guide to Data Manipulation in SQL

Learn to write accurate, readable SQL queries against any relational database β€” starting from zero and building to real-world complexity.

SQL Queries for Mere Mortals is a step-by-step guide for anyone who needs to retrieve and manipulate data but has never written a query before. Working through realistic sample databases, you build from simple SELECT statements to multi-table joins, subqueries, and aggregations β€” gaining the intuition to write SQL confidently, not just copy it from Stack Overflow.

About this book

Most SQL books assume you already think like a database. This one starts where you actually are: staring at a table full of data, knowing the answer is in there somewhere, and not yet sure how to ask for it.

SQL Queries for Mere Mortals walks you through the relational model in plain terms, then teaches you to write queries the way a working analyst or developer does β€” one clause at a time, with immediate feedback from real sample data. Author John Viescas has spent decades teaching SQL to people who do not have a computer-science background, and that experience shows in every explanation.

You start with single-table SELECT statements and filtering, then progress through sorting, grouping, and aggregate functions. From there the book covers inner and outer joins across multiple tables, subqueries, set operations, and the full range of modification statements: INSERT, UPDATE, and DELETE. Each concept is demonstrated against concrete sample databases β€” a bowling league, an entertainment agency, a school scheduling system β€” so you always have a meaningful context rather than abstract syntax.

By the time you finish, you will be able to:

  • Read and understand SQL written by someone else without guessing at intent
  • Write single- and multi-table queries that return exactly the rows you need
  • Use aggregate functions and GROUP BY to summarize data correctly
  • Construct subqueries and derived tables to break complex problems into steps
  • Modify data safely with INSERT, UPDATE, and DELETE
  • Spot common mistakes β€” Cartesian products, ambiguous column names, filter placement errors β€” before they reach production

The sample databases and exercises are compatible with all major relational databases, including MySQL, PostgreSQL, Microsoft SQL Server, and SQLite, so the skills transfer directly to whatever system you are working with. At 670 pages, this is the reference you return to when a new problem stumps you, not just the tutorial you read once and shelve.

If you have avoided SQL because it looked arcane, or if you have been writing queries by trial and error without really understanding why they work, this book closes that gap.

🎯 What you'll learn

  • Construct SELECT statements with precise filtering, sorting, and column expressions
  • Join two or more tables using inner, left, right, and full outer joins without producing accidental duplicates
  • Aggregate rows with GROUP BY, HAVING, COUNT, SUM, AVG, MIN, and MAX correctly
  • Write subqueries and correlated subqueries to solve problems that a single query level cannot handle
  • Modify table data safely using INSERT, UPDATE, and DELETE with proper WHERE conditions
  • Diagnose and fix common query mistakes including Cartesian products and misplaced filter predicates
  • Read and interpret SQL written by others so you can maintain and extend existing code

πŸ‘€ Who is this book for?

  • Analysts and business professionals who need to query databases but have no formal SQL training
  • Developers new to relational databases who want a rigorous foundation before writing application queries
  • Students taking a database course who need worked examples alongside their textbook theory
  • Self-taught SQL writers who want to fill the gaps left by tutorials and answer sites
  • Data professionals moving from spreadsheet tools to SQL-based reporting and want a structured transition

Table of contents

  1. 01

    Relational Databases and SQL

    Understand what a relational database is, how tables and relationships work, and where SQL fits in. You set up the sample databases used throughout the book.

  2. 02

    SELECT Statements and Filtering Rows

    Write your first queries using SELECT and WHERE to retrieve specific rows from a single table. Learn comparison operators, pattern matching with LIKE, and NULL handling.

  3. 03

    Sorting and Limiting Results

    Control the order and volume of query output using ORDER BY and row-limiting clauses. Understand why sort order is never guaranteed without an explicit ORDER BY.

  4. 04

    Aggregate Functions and Grouping

    Summarize data with COUNT, SUM, AVG, MIN, and MAX. Use GROUP BY and HAVING to compute per-group statistics and filter groups after aggregation.

  5. 05

    Joining Multiple Tables

    Retrieve data spread across two or more tables using INNER JOIN and the various forms of OUTER JOIN. Understand join conditions and how to avoid unintended Cartesian products.

  6. 06

    Subqueries and Derived Tables

    Break complex questions into smaller steps using subqueries in WHERE, FROM, and SELECT clauses. Build derived tables and correlated subqueries for problems that a flat join cannot solve.

  7. 07

    Set Operations

    Combine result sets from multiple queries using UNION, INTERSECT, and EXCEPT. Learn when set operations are clearer than equivalent joins or subqueries.

  8. 08

    Modifying Data

    Insert new rows, update existing values, and delete records using INSERT, UPDATE, and DELETE. Practice writing safe modification statements that target exactly the intended rows.

  9. 09

    Data Integrity and Constraints

    Understand how PRIMARY KEY, FOREIGN KEY, UNIQUE, and CHECK constraints protect your data. See how the database enforces rules that your queries must respect.

  10. 10

    Putting It All Together

    Solve a series of realistic, multi-step business questions using every technique from the book. Review common mistakes and build a checklist for writing and reviewing SQL in a real project.

Frequently asked questions

Do I need any prior programming or database experience?

No. The book assumes you know nothing about SQL or relational databases. It introduces every concept from scratch, including what a table and a relationship are, before writing a single query.

Which database system does the book use?

The examples are written in standard SQL and work with MySQL, PostgreSQL, Microsoft SQL Server, SQLite, and Microsoft Access. Sample databases are provided for the major platforms so you can follow along on whatever system you have.

Is this book suitable for someone who already knows basic SQL?

It depends on how solid your fundamentals are. Chapters 1 through 4 may be review, but the join, subquery, and set-operation chapters cover edge cases and common errors that many intermediate users have never properly examined.

Does the book cover stored procedures, triggers, or advanced performance tuning?

No. The focus is entirely on writing correct SELECT, INSERT, UPDATE, and DELETE statements. Topics like indexing strategy, stored procedures, and query optimization are outside its scope.

How current is the SQL covered relative to modern databases?

The book covers core ANSI SQL, which is stable across decades and supported by every major relational database in active use today. Vendor-specific syntax differences are noted where they matter.

Are there exercises I can practice with?

Yes. Each chapter includes review questions and hands-on exercises tied to the sample databases, so you can verify your understanding before moving to the next topic.

You might also like

πŸ“¬ Weekly Newsletter

Stay ahead of the curve

Get the best programming tutorials, data analytics tips, and tool reviews delivered to your inbox every week.

No spam. Unsubscribe anytime.