Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

218


Part II: Building Databases and Working with Data


in both tables. The Customer table rows and SalesOrderHeader table rows that match
merge into a new result:

CompanyName TotalDue
------------------------------------- ------------
Professional Sales and Service 43962.7901
Remarkable Bike Store 7330.8972
Bulk Discount Store 98138.2131
Coalition Bike Company 2669.3183
Futuristic Bikes 272.6468
Channel Outlet 608.1766
Aerobic Exercise Company 2361.6403
Vigorous Sports Store 1170.5376
Thrilling Bike Tours 15275.1977
Extreme Riding Supplies 63686.2708
Action Bicycle Specialists 119960.824
Central Bicycle Specialists 43.0437
The Bicycle Accessories Company 117.7276
Riding Cycles 86222.8072
Good Toys 972.785
Paints and Solvents Company 14017.9083
Closest Bicycle Store 39531.6085
Many Bikes Store 81834.9826
Instruments and Parts Company 70698.9922
Trailblazing Sports 45992.3665
Eastside Department Store 92663.5609
Sports Products Store 3673.3249
Discount Tours 3293.7761
Tachometers and Accessories 2228.0566
Essential Bike Works 45.1995
Engineered Bike Systems 3754.9733
Transport Bikes 665.4251
Metropolitan Bicycle Supply 108597.9536
West Side Mart 87.0851
Thrifty Parts and Sales 1261.444
Sports Store 2711.4098
Nearby Cycle Shop 42452.6519

Number of Rows Returned
It is rare that an inner join returns all the rows from all tables. The preceding query has 32
rows in the SalesLT.SalesOrderHeader table, which is the number of rows returned in
the query. However, 847 rows are in the SalesLT.Customer table, but only 32 rows in the
SalesLT.Customer table matched on the CustomerID column to the rows in the SalesLT
.SalesOrderHeader table. Depending on the number of matching rows from each data
source and the type of join, you can decrease or increase the fi nal number of rows in the
result set.

c09.indd 218c09.indd 218 7/30/2012 4:25:05 PM7/30/2012 4:25:05 PM


http://www.it-ebooks.info
Free download pdf