sql - How to get the combination of values from different columns in one table? -
i don't want insert row in table, want combination results.
for example, columns a,b,c.
value set {1,2} value set b {a,b} value set c {!,@} combination want are: 1 ! 1 @ 1 b ! 1 b @ 2 ! 2 @ 2 b ! 2 b @
assuming i've understood example schema correctly as:
create table test (a varchar(10), b varchar(10),c varchar(10)); insert test (a, b, c) values ('1', 'a', '!'); insert test (a, b, c) values ('2', 'b', '@');
then can do:
select t.a, t2.b, t3.c test t cross join test t2 cross join test t3 order t.a, t2.b, t3.c;
this uses cross join operation, produces cartesian product of 2 tables - i.e. every row matched every other row. it's lesser-used part of sql. there's explanation of here: http://www.w3resource.com/oracle/joins/oracle-cross-join.php
see working example of code here:
Comments
Post a Comment