Cartesian join two tables without records

I need to join table A (tax related) to table B (customer related)

I take no more than 1 record, but sometimes I do not record.

Now I need to return the combined record to the user

I though a simple Cartesian product would have work

SELECT * FROM TableA, TableB 

but this does not work if TableA or TableB is empty

I would make a full outer join, but right now I can’t join. I could create temporary tables with identity columns and then join them (since 1 = 1)

But I was looking for another way?

thanks

+4
source share
1 answer

According to your own suggestion, you can use full outer join to guarantee a string:

 select * TableA a full outer join TableB b on    1=1 

To always return at least one row, even if TableA and TableB are emtpy, you can use a fake table:

 select * from ( select 1 as col1 ) fake left join TableA a on 1=1 left join TableB b on 1=1 
+6
source

All Articles