I have two tables say MyFull
and MyEmpty
. I need to do the combination of all records from both tables. Sometimes, MyEmpty
table might have no records, in this scenario I need to return all records from MyFull
. This is what I have tried:
--Q1 >> returns no results
SELECT *
FROM MyFull CROSS JOIN MyEmpty
--Q2 >> returns no results
SELECT *
FROM MyFull, MyEmpty
I though of using LEFT JOIN
but I have no common key to join on. This is a SQLFiddle
Full table :
declare @t table (Spot int,name varchar(1),pct int)
insert into @t(Spot,name,pct)values(1,'A',2),(1,'B',8),(1,'C',6),(2,'A',4),(2,'B',5),(3,'A',5),(3,'D',1),(3,'E',4)
Empty table :
declare @tt table (Spot int,name varchar(1),pct int)
select * from @t OUTER APPLY @tt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With