Skip to content
Advertisement

MySQL join dataset on at least X items

My question in a SQL Fiddle.

How can I join all elements in table A with all elements in table B via a many-to-many mapping table, even if no relationship exists? My LEFT JOIN solution isn’t giving the results I expect.


Details:

Given these tables:

And this seed data:

I need a report like this:

The query I have tried (but doesn’t give satisfactory results):

Advertisement

Answer

Use a cross join to generate the rows and left join to bring in the values:

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