Skip to content
Advertisement

t-SQL cartesian production of several tables

I would like to get a cartesian product of several tables in SQL (which are actually only one column, so no common key). For example:

I tried CROSS JOIN, but I couldn’t find an example with multiple tables. Is the only way to do it is nesting? What if we have 15 tables to join that way… it creates a very long code.

Thank you!

Advertisement

Answer

You would simply use:

Do note that if any of the tables are empty (i.e. no rows), you will get no results.

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