Home All Groups Group Topic Archive Search About

generate three rows out of one row from a table

Author
19 Jan 2006 10:25 PM
sqlguy
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 advance

Author
19 Jan 2006 10:40 PM
Anith Sen
Use 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

AddThis Social Bookmark Button