JOINS in SQL | Inner Join | Left Join | Right Join | Full Join | SQL Beginner Series - Part 12

preview_player
Показать описание
This channel would provide new videos on SQL, ETL and Data warehouse concepts. I would create a separate play list for SQL Tutorials for beginners, advanced concepts, Interview questions and data warehousing concepts

--******************************************************************************************
-- Session 12 - --JOINS IN SQL
--******************************************************************************************
--INNER JOIN – Returns the common records between two tables

CREATE TABLE tblEmployee (Empid INT NULL
,EmpName Varchar(50) NULL
,Deptid INT NULL
)

CREATE TABLE tblDept (Deptid INT NULL
,DeptName Varchar(50) NULL
)

INSERT tblEmployee Values (1,'Emp5',NULL), (2,'Emp2',2),(3,'Emp3',3)
INSERT tblDept Values (1, 'HR'),(2, 'Finance'),(3,'IT'),(NULL,'Sales')

SELECT * FROM tblEmployee
SELECT * FROM tblDept
SELECT * FROM tblEmployee E
INNER JOIN tblDept D
ON E.Deptid = D.Deptid
--LEFT JOIN - Returns all the rows from Left table and matching rows between two tables
--LEFT JOIN = INNER JOIN + Records from Left table
SELECT * FROM tblEmployee
SELECT * FROM tblDept
SELECT * FROM tblEmployee E
LEFT JOIN tblDept D
ON E.Deptid = D.Deptid

--RIGHT JOIN – Returns all the rows from Left table and matching rows
--between two tables
--RIGHT JOIN = INNER JOIN + Records from Right table

SELECT * FROM tblEmployee
SELECT * FROM tblDept
SELECT * FROM tblDept D
RIGHT OUTER JOIN tblEmployee E
ON E.Deptid = D.Deptid

--FULL JOIN - Returns all the rows from two tables

SELECT * FROM tblEmployee
SELECT * FROM tblDept
SELECT * FROM tblDept D
FULL OUTER JOIN tblEmployee E
ON E.Deptid = D.Deptid

Facebook Page:

Youtube Channel:

#SQLWithRaviMartha #sql
#sqlserver #sqlqueries #Selectstatement
#etltesting #testing #sqlquery #ssms #database #databasetesting
#DBtesting #SQLJoins

Finding Missing Sequence Dates - Part 28 | Recursive CTE | DATEADD | Skipped Dates Using SQL
Рекомендации по теме