Professional Documents
Culture Documents
Joins: A Visual Explanation of SQL Joins
Joins: A Visual Explanation of SQL Joins
AVisualExplanationofSQLJoins
Assumewehavethefollowingtwotables.TableAisontheleft,andTableBisontheright. We'llpopulatethemwithfourrecordseach.
Let'sjointhesetablesbythenamefieldinafewdifferentwaysandseeifwecangeta conceptualmatchtothoseniftyVenndiagrams.
InnerjoinproducesonlythesetofrecordsthatmatchinbothTableAandTableB.
FullouterjoinproducesthesetofallrecordsinTableAandTableB,withmatchingrecords frombothsideswhereavailable.Ifthereisnomatch,themissingsidewillcontainnull.
LeftouterjoinproducesacompletesetofrecordsfromTableA,withthematchingrecords (whereavailable)inTableB.Ifthereisnomatch,therightsidewillcontainnull.
ToproducethesetofrecordsonlyinTableA,butnotinTableB,weperformthesameleftouter join,thenexcludetherecordswedon'twantfromtherightsideviaawhereclause.
ToproducethesetofrecordsuniquetoTableAandTableB,weperformthesamefullouter join,thenexcludetherecordswedon'twantfrombothsidesviaawhereclause.
There'salsoacartesianproductorcrossjoin,whichasfarasIcantell,can'tbeexpressedas aVenndiagram: