Special OFFER: 1st Enroll Flat 25% OFF OR 2nd Enroll Get 40% OFF | Use Coupon JTOFFER25

- SQL Server Blogs -

Different Type of SQL Joins

Joins in SQL server are used to retrieve data from two or more related tables. In general tables are related to each other using foreign key constraints.

In SQL server, there are different types of joins

  1. Inner Join
  2. Outer Join
  3. Cross Join

Outer Joins are again divided as

  1. Left Join or Left Outer Join
  2. Right Join or Right Outer Join
  3. Full join or Full Outer Join

Let’s understand Join types with examples and the differences between them.

Read More: Different Types of SQL Keys

1.Employee Table (tblEmployee) Different Type of SQL Joins

2.Department table (tblDepartment) Different Type of SQL Joins

  1. Inner Joins: -

Return only matching rows between both the tables. On matching rows are eliminated. Different Type of SQL Joins  

Read: Top 25 DB2 Interview Questions and Answers for Freshers & Experienced

SELECT Name,Gender,Salary,DepartmentName FROM tblEmployee INNER JOIN tblDepartment ON tblEmployee.DepartmentId=tblDepartment.Id

 

Read More: Different Types of SQL Database Functions

If you look at the output we got only 8 rows but in Employee table it has 10 rows. We didn’t got James and Russell records. This is because DepartmentId, in Employee table is NULL for these two employees and doesn’t match ID column in Department table. Different Type of SQL Joins

2.Left Join or Left Outer Join: -

Returns all the matching rows and non-matching row from left table. In reality, LEFT JOIN and INNER JOIN are extensively used.   Different Type of SQL Joins


 SELECT Name,Gender,Salary,DepartmentName FROM tblEmployee LEFT OUTER JOIN tblDepartment ON tblEmployee.DepartmentId=tblDepartment.Id

Different Type of SQL Joins

 

Read: SQL Developer Resume Guide - Complete SQL Resume Sample

3.Right Join or Right Outer: -

Returns all the matching rows and non-matching row from right table. Different Type of SQL Joins


 SELECT Name,Gender,Salary,DepartmentName FROM tblEmployee RIGHT JOIN tblDepartment ON tblEmployee.DepartmentId=tblDepartment.Id

Different Type of SQL Joins

 

4. Full Join or Full Outer Join: -

Returns all the rows from both left and right of the table, including non-matching rows. Different Type of SQL Joins


 SELECT Name,Gender,Salary,DepartmentName FROM tblEmployee FULL JOIN tblDepartment ON tblEmployee.DepartmentId=tblDepartment.Id

Different Type of SQL Joins

 

Read: MSBI Interview Questions & Answers for Fresher, Experienced

Cross Join: -

Read More: Different Types of SQL Injection

Cross Join produces the cartesian product of the two tables involved in the join. For example, in the employee table we have 10 records and in the department table we have 4 records. So as a cross join between two tables it will produce 40 records. Cross join shouldn’t have ON clause. Different Type of SQL Joins


 SELECT Name,Gender,Salary,DepartmentName FROM tblEmployee CROSS JOIN tblDepartment

 



SQL Tutorial Overview

FaceBook Google+ LinkedIn Pinterest

    Janbask Training

    A dynamic, highly professional, and a global online training course provider committed to propelling the next generation of technology learners with a whole new way of training experience.


Comments

Trending Courses

AWS

  • AWS & Fundamentals of Linux
  • Amazon Simple Storage Service
  • Elastic Compute Cloud
  • Databases Overview & Amazon Route 53

Upcoming Class

3 days 24 Sep 2021

DevOps

  • Intro to DevOps
  • GIT and Maven
  • Jenkins & Ansible
  • Docker and Cloud Computing

Upcoming Class

3 days 24 Sep 2021

Data Science

  • Data Science Introduction
  • Hadoop and Spark Overview
  • Python & Intro to R Programming
  • Machine Learning

Upcoming Class

4 days 25 Sep 2021

Hadoop

  • Architecture, HDFS & MapReduce
  • Unix Shell & Apache Pig Installation
  • HIVE Installation & User-Defined Functions
  • SQOOP & Hbase Installation

Upcoming Class

10 days 01 Oct 2021

Salesforce

  • Salesforce Configuration Introduction
  • Security & Automation Process
  • Sales & Service Cloud
  • Apex Programming, SOQL & SOSL

Upcoming Class

4 days 25 Sep 2021

QA

  • Introduction and Software Testing
  • Software Test Life Cycle
  • Automation Testing and API Testing
  • Selenium framework development using Testing

Upcoming Class

3 days 24 Sep 2021

Business Analyst

  • BA & Stakeholders Overview
  • BPMN, Requirement Elicitation
  • BA Tools & Design Documents
  • Enterprise Analysis, Agile & Scrum

Upcoming Class

3 days 24 Sep 2021

MS SQL Server

  • Introduction & Database Query
  • Programming, Indexes & System Functions
  • SSIS Package Development Procedures
  • SSRS Report Design

Upcoming Class

4 days 25 Sep 2021

Python

  • Features of Python
  • Python Editors and IDEs
  • Data types and Variables
  • Python File Operation

Upcoming Class

4 days 25 Sep 2021

Artificial Intelligence

  • Components of AI
  • Categories of Machine Learning
  • Recurrent Neural Networks
  • Recurrent Neural Networks

Upcoming Class

4 days 25 Sep 2021

Machine Learning

  • Introduction to Machine Learning & Python
  • Machine Learning: Supervised Learning
  • Machine Learning: Unsupervised Learning

Upcoming Class

17 days 08 Oct 2021

Tableau

  • Introduction to Tableau Desktop
  • Data Transformation Methods
  • Configuring tableau server
  • Integration with R & Hadoop

Upcoming Class

3 days 24 Sep 2021

Search Posts

Reset

Receive Latest Materials and Offers on SQL Server Course

Interviews