Head First SQL, 2nd Edition

Book description

What will you learn from this book?

Do you have an abundance of data but don't know how to make sense of it? Do you want to gain useful insights from your data, but you're not sure where to begin? Mining data is a vital, well-paying skill, and SQL provides the most fundamental way to query and manage data. But learning SQL can be intimidating. This thoroughly revised book teaches you SQL fundamentals in a painless and enjoyable manner. With the Head First series' hands-on, conversational style, you'll quickly grasp SQL concepts, then move to intermediate topics, including stored procedures and cloud databases. You'll gain the knowledge, skills, and confidence necessary to get the most out of your data with SQL.

Why does this book look so different?

If you've read a Head First book, you know what to expect: a visually rich format designed for the way your brain works. If you haven't, you're in for a treat. With this book, you'll learn about SQL through a multisensory experience that engages your mind—rather than a text-heavy approach that puts you to sleep.

Publisher resources

View/Submit Errata

Table of contents

  1. Brief Table of Contents (Not Yet Final)
  2. 1. Databases and Tables: Organizing Your Information
    1. Defining your data
    2. Think about your data in categories
    3. Build a table of information
    4. What is SQL?
    5. The anatomy of a table
    6. A table of travel data
    7. BE the table
    8. BE the table Solution
    9. What’s a database?
    10. Databases contain related information
    11. Take command!
    12. Your first SQL commands
    13. Creating a SQL table
    14. Steps for creating a general SQL table
    15. Your table is ready
    16. A selection of common data types
      1. Data types for text
      2. Data types for numbers
      3. Data types for dates and times
      4. A data type for other things
    17. Who am I?
    18. Your table, DESCribed
    19. Changing table properties
    20. Code Magnets
    21. Code Magnets Solution
    22. Dropping and recreating tables
    23. Adding a new column
    24. Hitting your cruising altitude
    25. SQLcross
    26. Your SQL toolbox
    27. Who am I? Solution
    28. SQLcross Solution
  3. 2. Inserting Data: Adding Table Rows
    1. Setting up a database with tables
    2. Checking back in with Abby
    3. Inserting data into tables
    4. Creating your INSERT statement
    5. See your table with SELECT
    6. A new recommendation
    7. Records with missing values
    8. Revisiting your table
    9. Controlling NULLs...
    10. ... and Setting DEFAULTs
    11. Variations on INSERT #1
    12. Variations on INSERT #2
    13. Variations on INSERT #3
    14. A punctuation problem
    15. Unmatched single quotes
    16. INSERT data with single quotes in it
    17. It’s only up from here!
    18. SQLcross
    19. Your SQL toolbox
    20. SQLcross Solution
  4. 3. The Select Statement: Finding Your Information
    1. Searching for a destination
    2. SELECT specific columns
    3. Specify columns... and their order
      1. SELECT specific columns for faster results
    4. An even better SELECT
    5. WHERE to next?
    6. WHERE filters out rows
    7. WHERE results
    8. Finding numeric values
    9. Expanding a numeric search
    10. Short travel times using less than
    11. Comparison Operators
    12. Finding numeric data with comparison operators
    13. Comparison operators for text
    14. Who am I?
    15. Who am I? Solution
    16. SQLcross
    17. Your SQL Toolbox
    18. SQLcross Solution
  5. 4. Better Where Clauses Filtering Rows
    1. Misplaced identification
    2. Multiple row requirements
    3. Combining your queries
    4. Use AND to satisfy two conditions
    5. To be OR not to be
    6. Code Magnets
    7. Code Magnets Solution
    8. Fireside Chats
    9. The difference between AND and OR
    10. BE the Conditional
    11. Be the Conditional Solution
    12. Use IS NULL to find NULLs
    13. IS NULL in your console
    14. Selecting ranges using AND and comparison operators
    15. Just BETWEEN us... there’s a better way
    16. Meanwhile, Abby dreams of sunshine...
    17. Save time with LIKE
    18. I’d LIKE to buy a wildcard, please
    19. You’re either IN...
    20. ... or you are NOT IN
    21. And that’s NOT all
    22. WHERE for the win
    23. SQLcross
    24. Your SQL toolbox
    25. SQLcross Solution
  6. 5. CRUD Operations Controlling Your Data
    1. What’s for dinner?
    2. Extracting information
    3. Getting to know CRUD
    4. Cubicle conversation
    5. Change your data with UPDATE
    6. Staying up-to-date with UPDATE
    7. UPDATE in your console
    8. Updating multiple columns or rows
    9. The price is wrong
    10. Revisiting CRUD
      1. Disheartening news
    11. Getting rid of rows with DELETE
    12. DELETE rules
    13. DELETE (+SELECT) in your console
      1. Test your WHERE with SELECT
      2. DELETE with the same WHERE
    14. CRUD complete
    15. SQLcross
    16. Your SQL toolbox
    17. SQLcross Solution
  7. 6. Advanced Select Sorting and Aggregating
    1. Shopping around
    2. ORDER (BY) in the court!
    3. ORDER with WHERE
    4. An orderly stores table
    5. Reverse the ORDER with DESC
    6. LIMIT the number of results
    7. Hitting the LIMIT
    8. SUM to add values for us
    9. SUM all of them at once with GROUP BY
    10. Imagine GROUP BY splitting your data
    11. Getting group averages
    12. MIN and MAX
    13. The COUNT of Monty Bristow
    14. SELECT DISTINCT values
    15. Filtering groups
    16. HAVING the right filter mechanism
    17. Easy as S.F.W.G.H.O.
    18. Your very own categorization
    19. A CASE for new groups
    20. SELECTing a CASE expression
    21. Go with the CASE flow
    22. Alias your columns with AS
    23. Even more power with aliasing
    24. An impressive list of abilities
    25. SQLcross
    26. Your SQL toolbox
    27. SQLcross Solution
  8. 7. Normalization and Multiple Tables Thoughtful Table Design
    1. Two mountainous tables
    2. A table is all about relationships
    3. Atomic data
      1. 30 minutes or it’s free
      2. Location, location, location
    4. Asking atomic questions
    5. More atomic updates
    6. Get into a normal routine
    7. What’s normal and 1NF?
    8. PRIMARY KEY to success
    9. Getting to normal
    10. The CREATE TABLE with a PRIMARY KEY
    11. 1, 2, 3... automatically
    12. Adding a PRIMARY KEY to an existing table
    13. ALTER TABLE to add a PRIMARY KEY
    14. Think outside of the single table
    15. Abby’s database schema
    16. Going from one table to two
    17. Querying two tables
    18. Connecting your tables
    19. FOREIGN KEY to success
    20. Constraining your foreign key
    21. CREATE a table with a FOREIGN KEY
    22. One-to-one
      1. When to use one-to-one tables
    23. One-to-many
    24. Many-to-many
    25. We need a junction table
    26. Fixing data patterns
    27. How normal can you be?
    28. Composite keys use multiple columns
      1. Even superheroes have dependencies
    29. Partial functional dependency
    30. Transitive functional dependency
    31. Second Normal Form (2NF)
    32. Third Normal Form (3NF)
    33. Your SQL toolbox
  9. 8. Alter Changing and Optimizing
    1. Summer camp chaos
    2. Ready for renovations
    3. Table altering
    4. Renaming our table
    5. Making a CHANGE
    6. Choosing your data types
      1. Minimizing disk space
    7. Storage considerations for text
    8. MODIFY a data type
    9. Slowing to a crawl
    10. INDEX for faster queries
    11. Two ways to INDEX
    12. Composite index ordering
    13. ALTER your awkward columns
      1. Look for patterns
    14. A few handy string functions
      1. To SELECT everything before the comma
      2. To SELECT the last two characters
    15. UPDATE with string functions
    16. Create data-filled tables
    17. Your SQL toolbox
  10. 9. Joins and Unions: Multiple-table Operations
    1. Time to JOIN the party
    2. The CROSS JOIN
    3. Filtering a CROSS JOIN
    4. Releasing your INNER JOIN
    5. The inner join in action
    6. Other ON conditions
    7. OUTER this world!
      1. Left (outer) join
    8. The left join in action
    9. Flipping your table order
    10. Outer joins and multiple matches
    11. Right (outer) join
    12. FULL OUTER JOIN
    13. A self-referencing foreign key
    14. Joining a table to itself
    15. We’re ready for a self join
    16. Another way to combine multiple tables
    17. You can use a UNION
      1. UNION bylaws
    18. UNION rules in action
    19. UNION ALL
    20. JOINing the fun at Camp Calloway
    21. Your SQL toolbox
  11. 10. Subqueries: Queries within Queries
    1. Low-budget options
    2. Two-step troubles
    3. Subqueries
    4. Combine the inner and outer queries
    5. A subquery as a SELECT column
    6. Subquery construction walk through
    7. Subqueries with multiple results
    8. Non-correlated subqueries
    9. Correlated subqueries
    10. A correlated subquery with NOT EXISTS...
      1. ...Or with EXISTS
    11. Click bait?
    12. Turning a subquery into a join
    13. FROM subqueries
    14. Common table expressions (CTEs)
    15. Derived tables vs. CTEs
    16. Subquery success
    17. Your SQL toolbox
  12. About the Author

Product information

  • Title: Head First SQL, 2nd Edition
  • Author(s): Kimberly Fessel
  • Release date: August 2026
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781098163655