I have a table in Oracle database and it has lot of records. That table has a column "type" that specifies type of each record. I wanted to do cross join records of different types.
Assume this table "RecordTypes"
Name Type Group
1name1 1 1
1name2 1 1
2name1 2 1
2name2 2 2
3name1 3 3
3name2 3 3
I want a query to cross join on the rows of this table based on Type column. In this table there are 3 types of records based on "Type" column. The query should produce this result.
Type1 Type2 Type3
1name1 2name1 3name1
1name1 2name1 3name2
1name1 2name2 3name1
1name1 2name2 3name2
1name2 2name1 3name1
1name2 2name1 3name2
1name2 2name2 3name1
1name2 2name2 3name2
I can produce this result based on this query, but I have hardcoded the type value. In realtime, I don’t know what and how many distinct values will be there for "Type" column.
With type1 as (select name from table where type = 1),
Type2 as (select name from table where type = 2),
Type3 as (select name from table where type = 3)
Select * from type1, type2, type3.
I want a query/stored procedure to return the result where the stored proc should find the distinct type value available and return the result as above. Also, from the result I need to remove the records when 2 or more columns in a row belong to same "Group".