sql to get combination of all the given values

 

 

 

 

drop table t1;

drop table t2;

create table t1(c varchar2(1));

 

insert into t1 values('A');

insert into t1 values('B');

insert into t1 values('C');

 

create table t2(c varchar2(1));

 

insert into t2 values('D');

insert into t2 values('E');

insert into t2 values('F');

 

commit;

 

select * from t1

union

select * from t2;

 

with t as

(select * from t1

union

select * from t2)

select * from t a1,t a2;

 

 

with t as

(select * from t1

union

select * from t2)

select * from t a1,t a2

where a1.c<a2.c  order by 1;

 

with t as

(select * from t1

union

select * from t2)

select * from t a1,t a2

where a1.c<a2.c  order by 1;

 

with t as

(select * from t1

union

select * from t2)

select a1.c||'-'||a2.c output from t a1,t a2

where a1.c<a2.c  order by 1;

---------------------------------------------------------------------------------------

with t as

(select * from t1

union

select * from t2)

select a1.c,a2.c

from  t a1,t a2

 order by 1;

 

with t as

(select * from t1

union

select * from t2)

select a1.c,a2.c

from  t a1,t a2

where a1.c<>a2.c  order by 1;

 

with t as

(select * from t1

union

select * from t2)

select distinct least(a1.c,a2.c)||'-'||greatest(a1.c,a2.c) output

from  t a1,t a2

where a1.c<>a2.c  order by 1;

No comments:

Post a Comment