Chapter 4

JOINs

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • How to combine data from multiple tables into a single result set
  • How to select rows with matching keys
  • Including unmatched rows in your JOIN
  • How to generate massive amounts of data with a Cartesian product
  • What JOIN syntax might look like in older code
  • How to stack multiple result sets together

Feel like a seasoned professional yet? Let me dash that feeling right away (just kidding)! While you now have the basic statements under your belt, they are only a small part of the bigger picture of the statements you will run. To put it simply, there is often not that much you can do with just one table — especially in a highly normalized database.

A normalized database is one where the data has been broken out from larger tables into many smaller tables for the purpose of eliminating repeating data, saving space, improving performance, and increasing data integrity. It’s great stuff and vital to relational databases; however, it also means that you wind up getting your data from here, there, and everywhere.

imageNOTE You’ll look into the concepts of normalization extensively in Chapter 8. For now, though, just keep in mind that the more normalized your database is, the more likely you’re going to have to join multiple tables together in order to get all the data you want.

This chapter introduces you to the process of combining tables ...

Get Beginning Microsoft® SQL Server® 2012 Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.