Instagram
youtube
Facebook
Twitter

MS SQL Server Joins

MS SQL Server JOIN Clause

  • SQL Join Clause is used to merge two or more tables based on a common attribute.
  • There are mainly four types of SQL Server Join: Inner Join, Left Outer Join, Right Outer Join, Full Outer join

INNER JOIN(Simple Join)

  • It is a common type of join that returns all rows from multiple tables where the join condition is met.
  • Syntax:
SELECT columns FROM table1 INNER JOIN table2 ON table1.column=table2.column;

Example:

SELECT student.id, student.name FROM student INNER JOIN staff ON Student.Branch=staff.Branch;

 

LEFT OUTER JOIN

  • LEFT OUTER JOIN is a type of join that returns the left side of the table where join condition is met.
  • Syntax:
SELECT columns FROM table1 LEFT [OUTER] JOIN table2 ON table1.column = table2.column;

Example:

SELECT student.id, student.name FROM student LEFT OUTER JOIN staff ON Student.Branch=staff.Branch;

 

RIGHT OUTER JOIN

  • RIGHT OUTER JOIN is a type of join that returns the Right side of the table where join condition is met.
  • Syntax:
SELECT columns FROM table1 RIGHT [OUTER] JOIN table2 ON table1.column = table2.column;

Example:

SELECT student.id, student.name FROM student RIGHT OUTER JOIN staff ON Student.Branch=staff.Branch;

 

 FULL OUTER JOIN

  • FULL OUTER JOIN is a type of join that returns both Left side and Right side of the table where join condition is met.
  • Syntax:
SELECT columns FROM table1 FULL [OUTER] JOIN table2 ON table1.column = table2.column;

Example:

SELECT student.id, student.name FROM student FULL OUTER JOIN staff ON Student.Branch=staff.Branch;