254 Part I EXAM PREPARATION INSERT INTO Product

254 Part I EXAM PREPARATION INSERT INTO Product VALUES (38, Grommet ) INSERT INTO Product VALUES (39, Spackle ) INSERT INTO Product VALUES (51, Sparkle Dust ) INSERT INTO Product VALUES (47, Shoe Polish ) INSERT INTO Product VALUES (38, Varnish ) INSERT INTO Product VALUES (41, Lava ) go SELECT COUNT(*) FROM person –9 rows SELECT COUNT(*) FROM address –6 rows SELECT COUNT(*) FROM PersonAddress –9 rows SELECT COUNT(*) FROM Sales –8 rows SELECT COUNT(*) FROM Product –7 rows That s a lot of typing, but you ll end up using that data all the way through the chapter. Notice that several tables have data in them. You re probably wondering how to make them all work together. So now it s time to talk about join mechanics. Join Mechanics Whenever you query data from two tables, you need to find some way to relate the two tables together. If you need to select out the name and address of everyone in the example database, how would you go about doing it? You d want to write a query that would relate the Person table to the Address table through the PersonAddress table. Whenever you want to use a SQL statement to relate one table to another, it s called a join. In this case, you need two joins: one from the Person table to the PersonAddress table, and another one from the PersonAddress table to the Address table. Whenever you want to see a resultset that includes columns from several tables, you need to use a join. There are three basic join types. An inner join shows results only where there are matches between the elements. In other words, if you query the database and want to see only the people who have addresses, you use an inner join. An inner join leaves out all the records that don t have a match. An outer join can show all the records from one side of the relationship, records that match where they are available, and NULL values for records that do not have a match. An outer join between the Person and Sales tables can show you each person and the amount

For reliable and cheap web hosting services please check tomcat web hosting website.

Comments are closed.