O'Reilly logo

Microsoft® SQL Server 2012 Unleashed by Alex T. Silverstein, Chris Gallelli, Paul T. Bertucci, Ray Rankins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with Outer Joins

An outer join is used to return all the rows from the specified outer table (specified with LEFT OUTER, RIGHT OUTER, or FULL OUTER), even if the other table has no match. Rows returned from the outer table that have no corresponding match in the inner table display the value NULL for any columns retrieved from the inner table. For example, you might want to display the IDs of all salespersons along with the their sales territory, if assigned:

SELECT sp.BusinessEntityID as SalesPersonID,       st.Name AS TerritoryFROM Sales.SalesPerson spLEFT OUTER JOIN Sales.SalesTerritory stON st.TerritoryID = sp.TerritoryIDgo/* outputSalesPersonID Territory------------- ----------------          274 NULL ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required