0

When is direct product of two tables useful? Seems like an academic thing.

fastcodejava
  • 39,895
  • 28
  • 133
  • 186
  • 3
    possible duplicate of [What are the uses for Cross Join?](http://stackoverflow.com/questions/219716/what-are-the-uses-for-cross-join) – Will A Sep 14 '10 at 06:40

3 Answers3

2

Check out What are the uses for cross join?

Community
  • 1
  • 1
Will A
  • 24,780
  • 5
  • 50
  • 61
2

There are some uses for it. Let's say there is a clothing store selling T-Shirts in different colours and different sizes. Each combo has it's own SKU.

If there is a table Products that references tables Sizes and Colors then

You could get list of all possible products with:

SELECT * FROM Products, Colors, Sizes

Okay that is actually quite academic.

Benbob
  • 13,876
  • 18
  • 79
  • 114
  • I just checked out 'What are the uses for cross join?' and there is also a color sizes example. – Benbob Sep 14 '10 at 06:47
1

Some times you want to get every possible combination of rows that match certain criteria. The way to do it is cross-join and then filter out rows that do not match the criteria.

Inner/Outer joins are just a special case of this: the desired criteria is "the data of table 1 is related to the data in table2..."

gpeche
  • 21,974
  • 5
  • 38
  • 51