Skip to content
Advertisement

Joining to return all rows even when there are no results

I’m trying to get a list how many products we’ve sold, per company, by all categories.

I’d like the results to look like:

So every category is returned, every company is returned, even if there are no sales.

This is the query I’m trying and it should make the structure of the database clear. I’ve attacked this from a bunch of direction, but can’t seem to wrap my head around how to get at what I’m looking for.

Thanks for any help…

Advertisement

Answer

Generate the rows with a cross join, then left join in the rest of the information:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement