'Required help on cross join type query
I have data in my table like
| Country |
|---|
| Ind |
| Pak |
| Aus |
And I want to display output like
| Ind Vs Aus |
| Ind Vs Pak |
| Aus Vs Pak |
I tried below query
with cntry as
(
select 'ind' cnt from dual union all
select 'pak' from dual union all
select 'aus' from dual
)
select x.cnt, y.cnt from cntry x
cross join lateral
(
select cnt from cntry y
where x.cnt!=y.cnt
) y
But the output is not as per my requirement.
Solution 1:[1]
Just join.
SQL> WITH
2 cntry
3 AS
4 (SELECT 'ind' cnt FROM DUAL
5 UNION ALL
6 SELECT 'pak' FROM DUAL
7 UNION ALL
8 SELECT 'aus' FROM DUAL)
9 SELECT x.cnt, y.cnt
10 FROM cntry x JOIN cntry y ON x.cnt < y.cnt;
CNT CNT
--- ---
aus ind
aus pak
ind pak
SQL>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Littlefoot |
