Relating unrelated rows
3 Comments
A recurring question in the newsgroups is: “How do I output unrelated rows side by side?” I’ll use the AdventureWorks database as an example. Suppose that my manager wants a report listing, for each order, all products ordered and all reasons the customer has for ordering from AdventureWorks. Here’s a sample of how the report should look. SalesOrderNumber ProductID Reason SO51318 858 Other SO31518 870 Price SO31518 872 NULL SO31518 997 NULL SO31519 870 On Promotion SO31519 999 Price Getting a list of all products ordered for each order is a trivial affair: SELECT soh.SalesOrderNumber, sod.ProductID…
Read More