Wednesday, 13 November 2013

SQL Joins -- Visual Representation Part 1

SQL -- Joins My Visual Representation Part 1

My Favorite website I have with regards to this is Coding Horror Blog
and this is my Quick Representation of this.

Here are my two tables with the link being the Foreign key between the two tables.

Person
ID Name Link
1 Bjorn 1
2 Matthew 3
3 Monique
4 Kevin
5 Sean

Animal
ID Name
1 Bear
2 Fish
3 Dog
4 Bird
5 Spider

SQL Joins

Select Person.Name, Animal.name from Person Inner Join on Person.Link = Animal.ID

Inner Join

Bjorn Bear
Matthew Dog

Inner Join Venn Diagram

Select Person.Name, Animal.name from Person Full Outer Join on Person.Link = Animal.ID

Full Outer Join

Bjorn Bear
Matthew Dog
Monique
Kevin
Sean
Fish
Bird
Spider

Full Outer join Venn Diagram

Select Person.Name, Animal.name from Person left Outer Join on Person.Link = Animal.ID

Left Outer Join

Bjorn Bear
Matthew Dog
Monique
Kevin
Sean

Left Outer Join Venn Diagram

Select Person.Name, Animal.name from Person Right Outer Join on Person.Link = Animal.ID

Right Outer Join

Bjorn Bear
Fish
Matthew Dog
Bird
Spider




Add Some where clauses and you can go from the basic Joins, to some nice complex Results.

#bearMan