Introduction to SQL Joins Presentation:

SQL joins are used to fetch data from two or more tables from the database, using join condition. A join condition creates a relationship among columns in the data tables that take part in sql join. Data tables are linked with each other using keys, these key relationships are used in sql joins. Join is a process of combining tables side-by-side (horizontally)

When data from more than one table is required from database, a join condition is used. According to common values exist in columns; a row in one table can be joined to row in another table, i.e., usually primary and foreign key columns.

Different types of Joins:

  1. Inner Join: returns only those records or rows that match in both the tables

Syntax:       select * from table1 as t1

                   Inner join table2 as t2

                   On t1.column = t2.column

  1. Outer Join:

Three types of Outer join are:

  1. Left Outer Join: returns all records or rows from left table and right table returns only matched records. NULL is returned if no columns in right table are matching.

Syntax: select * from table_1 as t_1

              Left outer join table_2 as t_2

              On t_1.column=t_2.column

  1. Right Outer Join: returns all records or rows from right table and left table returns only matched records. If no matching columns in left table, it returns NULL.

Syntax: select * from table_1 as t_1

              Right outer join table_2 as t_2

              On t_1.column = t_2.column

  1. Full Outer Join: combines or joins both left outer join and right outer join. All records or rows from both tables are returned as a result. If no matching columns are found in both the tables then NULL is returned.

Syntax:  select * from table_1 as t_1

              Full outer join table_2 as t_2

              On t_1.column = t_2.column

  1. Cross Join: it is a Cartesian join of both tables. No condition is required to join two tables. Cross join returns records or rows that are multiplication of record number from both tables, means each row on left table will relate to each row of right table.

Syntax:  select * from table_1

              Cross join table_2

  1. Self Join: is used to join database table to itself, when table has a foreign key that references its own primary key. Self join is not a type of sql join.

Download  SQL Joins Presentation .