I need run a query that is like an left/right outer join. In other words I need all rows from both the left and right tables. But I don't need a cartesian product (cross join). I need to match on, in my case, email address. So given that, I have to output all rows from the left table, join the right table on email address, but all rows that do not match from either the left or right table need to be output as well with nulls for the fields from the opposite table. Sort of like a = join if there were such a thing, or left-righ outer join.
As for what I've tried: Google Searches. But didn't find anything. Cross apply might work, but I cannot wrap my brain around how that is any different from a join.
Example theoretical left-right join:
select users.*, contacts.*
from users
left-right join contacts on users.emailAddress = contacts.emailAddress
So if users contains:
---------------------------------- |emailAddress | firstName | ---------------------------------- |k@company.com | ken | |b@enterprise.com | bill | |j@establishment.com | joe | ----------------------------------
And contacts contains:
-------------------------------- |emailAddress | optedOut | -------------------------------- |z@bigcompany.com | 0 | |b@enterprise.com | 1 | |h@smallcompany.com | 1 | --------------------------------
The output should look like:
------------------------------------------------------------------ |emailAddress | firstName |emailAddress | optedOut | ------------------------------------------------------------------ |k@company.com | ken | NULL | NULL | |b@enterprise.com | bill | b@enterprise.com | 1 | |j@establishment.com | joe | NULL | NULL | |NULL | NULL | z@bigcompany.com | 0 | |NULL | NULL | h@smallcompany.com | 1 | ------------------------------------------------------------------