2

The question sounds confusing, but just look:

This way we can get the first column (col1):

select distinct maker
from product

And the second column (col2):

select distinct type,maker
from product

So now I need to get all possibly combinations from col1 and col2. Any suggestion?

Shortly, this:

A f1

B f2

Should become this:

A f1

A f2

B f1

B f2

P.S. This query won't return that I need.

select distinct A.maker, B.type
from product as A
Rocketq
  • 5,423
  • 23
  • 75
  • 126

2 Answers2

7

Use cross join to get all combinations:

select m.maker, t.type
from (select distinct maker from product) m cross join
     (select distinct type from product) t;

This is ANSI SQL syntax and should be supported in any database.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
1

variant using cross join but without subqueries will give same result as in @Gordon Linoff post, so you will get all possible combinations

select distinct A.maker, B.type
from product as A cross join product as B
Vasily
  • 5,707
  • 3
  • 19
  • 34