Reputation: 49
I have two tables, hotel and interests. I'd like to find the distance between each hotel and each interests. I tried using CROSS JOIN but my boss told me to not use cross join. Is there any other way? Implicit join and ON 1=1 is not allowed either. I was told to use join and brackets but I don't understand how is it possible to perform a cross join without using cross join. I'm using oracle sql by the way
Upvotes: 0
Views: 2310
Reputation: 2863
You don't need any extra syntax to carry out a cross join using Oracle sql.
Just listing the tables and not giving a join condition will give you the cartesian product that you're after
select table1.*, table2.*
from table1, table2
Upvotes: 2
Reputation: 49
After searching around I found that you can use < and > in ON. So I tried this:
SELECT * FROM a JOIN b ON (a.x<>b.x OR a.x=b.x)
And it seems to work just like a CROSS JOIN.
Upvotes: -3
Reputation: 222482
Well, if both tables have no column in common, you can do a NATURAL JOIN
: it will generate a cartesian product (also called CROSS JOIN
):
select t1.*, t2.* from table1 t1 natural join table2 t2
with
a as (select 1 as ida from dual union all select 2 from dual),
b as (select 3 as idb from dual union all select 4 from dual)
select a.*, b.* from a natural join b
IDA | IDB --: | --: 1 | 3 1 | 4 2 | 3 2 | 4
Other options (but apparently you are not allowed to use them):
Explicit join on 1=1
select t1.*, t2.* from table1 t1 inner join table2 t2 on 1 = 1
Implicit join:
select t1.*, t2.* from table1 t1, table2 t2
Upvotes: 5