36

I have two tables, one of them has weeks of year, and the second table has categories. I need to create a table that contains each week and each category, but there's no fields/keys that intersect in two tables:

Table 1:

week1
week2
week3
week4

Table 2:

Cat1
Cat2

Resulting table:

week1 cat1
week1 cat2
week2 cat1
week2 cat2
...
week4 cat1
week4 cat2

I'd like to do this without using many cursors/looping.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
dirol
  • 363
  • 1
  • 3
  • 4

2 Answers2

83
SELECT * FROM Table1 CROSS JOIN Table2

This will get you every combination of all columns from Table1 and Table2.

Matthew Jones
  • 25,644
  • 17
  • 102
  • 155
  • duh! of course. sometimes i think of more complicated ways around simple problems. thanks! – dirol Nov 25 '09 at 16:00
18

Have you tried just

 SELECT * FROM table1, table2
Valentin Golev
  • 9,965
  • 10
  • 60
  • 84