0% found this document useful (0 votes)
38 views4 pages

Joins: A Visual Explanation of SQL Joins

The document explains different types of SQL joins including inner joins, full outer joins, left outer joins, and cross joins. It uses tables and Venn diagrams to visually demonstrate how each join combines records from two tables based on matching fields.

Uploaded by

dsunismine
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views4 pages

Joins: A Visual Explanation of SQL Joins

The document explains different types of SQL joins including inner joins, full outer joins, left outer joins, and cross joins. It uses tables and Venn diagrams to visually demonstrate how each join combines records from two tables based on matching fields.

Uploaded by

dsunismine
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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:

Thisjoins"everythingtoeverything",resultingin4x4=16rows,farmorethanwehadinthe originalsets.Ifyoudothemath,youcanseewhythisisaverydangerousjointorunagainst largetables.

You might also like