user1896017
user1896017

Reputation: 83

cartesian product on two tables

I'm trying to create a result set of table names and column names. In table A I have the list of table names and in Table B I have the list of column names. Each table should have the full list of columns. So:

table_name
Table1
Table2
column_name
Column1
Column2
Column3

The result I want is:

table_name column_name
Table1 Column1
Table1 Column2
Table1 Column3
Table2 Column1
Table2 Column2
Table2 Column3

So I have select

select
        table_name
        column_name
from
        A
full outer join
        B
on
        A.TABLE_NAME = B.COLUMN_NAME

Which gives me:

table_name column_name
Table1
Table2
Column1
Column2
Column3

Close, but no cigar! How can I get my answer please?

Upvotes: 0

Views: 1304

Answers (2)

memo
memo

Reputation: 177

try this if your tables are not too big:

select
    A.table_name
    , B.column_name
from A
cross join B

Upvotes: 0

Mana S
Mana S

Reputation: 519

Use this:

select A.table_name, B.column_name from A, B;

Upvotes: 1

Related Questions