7
randomr
7y

So back to the stories of the gentleman with his master's degree who's job I wasn't qualified for. Hope you all enjoy this gem I found in his stored procedure.

Select distinct *
From(
Select * from a inner join b on a.id=b.id
Union
Select * from a full join b on a.id=b.id
Where b.id is null
)

An inner join unioned to a full join where you exclude null values in right table creates a.....left join you fucking idiot!

Comments
  • 1
    You need a master's degree for SQL?
  • 0
    @mightyleguan he was hired as an advanced data analyst. Works for a department that distributes dashboards and bi related tools to end users, mainly management.
  • 1
  • 0
    Doesn't it include null values of right table? So it would be right join?
  • 0
    @sSam nope. Left join is all records in left table and any that match b table. When you do a full join and include where b is null you eliminate all records where a and b match as well as all rows that have b and not an a. This leaves you with all of the a table that doesn't have match in b table.
    The top innerjoin gives you the ones that match. Combine the data sets with union and you have a left join.
Add Comment