Friday, March 9, 2012

generate three rows out of one row from a table

i've two tables as shown below, i want to generate the table2 using table1,
more details -- for each in table1 i want three rows in table2 these three
rows col2 says A, B, C
table1
--
c1
--
1
2
3
table2
--
c1 c2
-- --
1 A
1 B
1 C
2 A
2 B
2 C
3 A
3 B
3 C
thanks in advanceUse a cartesian product -- CROSS JOIN in SQL.
SELECT c1, c2
FROM table1
CROSS JOIN ( SELECT 'A' UNION
SELECT 'B' UNION
SELECT 'C' ) D ( c2 ) ;
Anith

No comments:

Post a Comment