Joins
AVisualExplanationofSQLJoins
[Link],andTableBisontheright. We'llpopulatethemwithfourrecordseach.
Let'sjointhesetablesbythenamefieldinafewdifferentwaysandseeifwecangeta conceptualmatchtothoseniftyVenndiagrams.
InnerjoinproducesonlythesetofrecordsthatmatchinbothTableAandTableB.
FullouterjoinproducesthesetofallrecordsinTableAandTableB,withmatchingrecords [Link],themissingsidewillcontainnull.
LeftouterjoinproducesacompletesetofrecordsfromTableA,withthematchingrecords (whereavailable)[Link],therightsidewillcontainnull.
ToproducethesetofrecordsonlyinTableA,butnotinTableB,weperformthesameleftouter join,thenexcludetherecordswedon'twantfromtherightsideviaawhereclause.
ToproducethesetofrecordsuniquetoTableAandTableB,weperformthesamefullouter join,thenexcludetherecordswedon'twantfrombothsidesviaawhereclause.
There'salsoacartesianproductorcrossjoin,whichasfarasIcantell,can'tbeexpressedas aVenndiagram:
Thisjoins"everythingtoeverything",resultingin4x4=16rows,farmorethanwehadinthe [Link],youcanseewhythisisaverydangerousjointorunagainst largetables.