Chapter 4. Putting Data Together with Joins
In This Chapter
Using SQL functions
Creating calculated fields
Working with date values
Creating inner joins and link tables
Single tables aren't sufficient for most data. If you understand the rules of data normalization (see Chapter 3 of this minibook), you know how to break your data into a series of smaller tables. The question remains, though: How do you recombine all these broken-up tables to make something the user can actually use?
In this chapter, you discover several techniques for combining the data in your tables to create useful results.
I wrote a quick PHP script to help me with most of the figures in this chapter. Each SQL query I intend to look at is stored in a separate SQL file, and I can load up the file and look at it with the PHP code. Feel free to look over the code for
showQuery on the CD-ROM. If you want to run this code yourself, be sure to change the username and password to reflect your data settings. I also include a script called
buildHero.sql that creates a database with all the tables and views I mention in this chapter. Feel free to load that script into your database so that you can play along at home.
Calculating Virtual Fields
Part of data normalization means that you eliminate fields that can be calculated. In the hero database described in Chapter 3 of this minibook, data normalization meant that you don't store the hero's age, but his or her birthday instead (see Chapter 3 of this minibook). ...