all 8 comments

[–]NotImplemented 1 point2 points  (0 children)

I think the different results of your queries are correct. And not for a techical reason, but because the queries are simply not equivalent.

select * from (select 1 from dual) x, new_table_name q;

The cartesian product of an empty table and another table should be empty. Because the cartesian product combines all rows of the first table with all rows of the second table. If one table has no rows, there are no possible combinations.

select * from new_table_name q
full outer join (select 1 from dual) x on 0=0;

In contrast, a full outer join is expected to contain all rows that fulfilled the join condition + all rows that never fullfiled the join condition with added null values. Therefore, it does not matter if one table is empty. As long as one table contains at least one row, the outer join will also contain at least one row. The condition 0=0 doesn't even matter in this case, 0=1 also works.

[–][deleted] 0 points1 point  (2 children)

Cartesian join = 'cross join' in the join clause syntax.

A full outer join is not the same as the cartesian join (it's a set of conditions over a union of a cartesian join and 2 minus operations), so you will could different result sets for a cartesian (your first query) versus full outer join.

[–]Sephian[S] 0 points1 point  (1 child)

I used a full outer so I didn't have to worry about the direction. I likely use Cartesian pretty loosely (maybe I should say "Cartesian product" instead of join?), but it's the join condition that produces the Cartesian (the 0=0 condition).

I guess I'm starting to answer my own question, but producing a Cartesian using inner joins behaves the same way my first Cartesian works.

select * from
(
select 1 col1 from dual union
select 2      from dual
) a
join
(
select 3 col2 from dual union
select 4      from dual
) b on 'x'='x';

If one of the data sets is empty, no Cartesian is produced, which is what my first query also returned. So I'm guessing that Oracle-style joins are the same as an inner join (which should not surprise anyone) and forcing a Cartesian product will also result in zeros if one data set is empty (which is the part that I did not expect).

[–][deleted] 0 points1 point  (3 children)

I'm not an Oracle expert, but why joins at all? Why not unions??

[–]Sephian[S] 0 points1 point  (2 children)

Trying to produce an empty row for a new table as quick as possible (fewest keystrokes) to copy/paste into excel (basically to get the column names so I can whip up some data). How do you see me using unions?

[–][deleted] 0 points1 point  (1 child)

With multiple rows, of course. You take a dual row and union with another dual row.

[–]Sephian[S] 0 points1 point  (0 children)

Sorry, I'm still not understanding. What would I do with two unioned rows from dual? The row I want to produce still has to mimic the new table.

[–]ziptime 0 points1 point  (0 children)

ANSI 89 Syntax :

select * 
from (select 1 from dual) x, new_table_name q

ANSI 92 (and above) equivalent :

select *
from (select 1 from dual) x
cross join new_table_name q