0% found this document useful (0 votes)
34 views5 pages

89 Intersect Operator in SQL Server

This document is a video tutorial on the INTERSECT operator in SQL Server, explaining its function to retrieve common records from two queries. It highlights the differences between INTERSECT and INNER JOIN, particularly in how they handle duplicates and NULL values. The tutorial includes examples using SQL scripts and provides additional resources for learning about SQL and .NET technologies.

Uploaded by

ayogbadebori
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views5 pages

89 Intersect Operator in SQL Server

This document is a video tutorial on the INTERSECT operator in SQL Server, explaining its function to retrieve common records from two queries. It highlights the differences between INTERSECT and INNER JOIN, particularly in how they handle duplicates and NULL values. The tutorial includes examples using SQL scripts and provides additional resources for learning about SQL and .NET technologies.

Uploaded by

ayogbadebori
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

3/12/2023 Sql server, .

net and c# video tutorial: Intersect operator in sql server


The Wayback Machine - https://web.archive.org/web/20211022010219/https://csharp-video-tutorials.blogspot.com/2015/09/intersect-operator-i…

Sql server, .net and c# video tutorial


Free C#, .Net and Sql server video tutorial for beginners and intermediate programmers.

Support us .Net Basics C# SQL ASP.NET Aarvi MVC Slides C# Programs Subscribe Download

Intersect operator in sql server

Suggested Videos
Part 86 - How to find blocking queries in sql server
Part 87 - SQL Server except operator
Part 88 - Difference between except and not in sql server

Pragim Technologies - Best software


training and placements in marathahalli,
bangalore. For further details please call
09945699393.

Complete Tutorials
How to become a full stack web
developer

Cloud computing complete tutorial

In this video we will discuss Healthy food for healthy mind and
1. Intersect operator in sql server body
2. Difference between intersect and inner join
JavaScript tutorial

Bootstrap tutorial

Angular tutorial for beginners

Angular 5 Tutorial for beginners

https://web.archive.org/web/20211022010219/https://csharp-video-tutorials.blogspot.com/2015/09/intersect-operator-in-sql-server.html 1/5
3/12/2023 Sql server, .net and c# video tutorial: Intersect operator in sql server

Important Videos
The Gift of Education

Web application for your business

How to become .NET developer

Resources available to help you

Dot Net Video Tutorials


Blazor tutorial

C tutorial

ASP.NET Core Tutorial


Intersect operator retrieves the common records from both the left and the right
query of the Intersect operator. ASP.NET Core Razor Pages Tutorial
Introduced in SQL Server 2005
Angular 6 Tutorial
The number and the order of the columns must be same in both the queries
The data types must be same or at least compatible Angular CRUD Tutorial
Let us understand INTERSECT operator with an example.
Angular CLI Tutorial

We will use the following 2 tables for this example. Angular 2 Tutorial

Design Patterns

SOLID Principles

ASP.NET Web API

Bootstrap

SQL Script to create the tables and populate with test data AngularJS Tutorial
Create Table TableA
( jQuery Tutorial
Id int,
JavaScript with ASP.NET Tutorial
Name nvarchar(50),
Gender nvarchar(10)
JavaScript Tutorial
)
Go Charts Tutorial

Insert into TableA values (1, 'Mark', 'Male') LINQ


Insert into TableA values (2, 'Mary', 'Female')
Insert into TableA values (3, 'Steve', 'Male') LINQ to SQL
Go
LINQ to XML
Create Table TableB
Entity Framework
(
Id int, WCF
Name nvarchar(50),
Gender nvarchar(10) ASP.NET Web Services
)
Go Dot Net Basics

C#
Insert into TableB values (2, 'Mary', 'Female')
Insert into TableB values (3, 'Steve', 'Male')
SQL Server
Go
ADO.NET
The following query retrieves the common records from both the left and the right query
of the Intersect operator. ASP.NET

Select Id, Name, Gender from TableA GridView


Intersect
ASP.NET MVC
Select Id, Name, Gender from TableB
Visual Studio Tips and Tricks
Result :
Dot Net Interview Questions

Slides
https://web.archive.org/web/20211022010219/https://csharp-video-tutorials.blogspot.com/2015/09/intersect-operator-in-sql-server.html 2/5
3/12/2023 Sql server, .net and c# video tutorial: Intersect operator in sql server

Entity Framework

WCF

ASP.NET Web Services

Dot Net Basics


We can also achieve the same thinkg using INNER join. The following INNER join query
would produce the exact same result. C#

Select TableA.Id, TableA.Name, TableA.Gender SQL Server


From TableA Inner Join TableB
ADO.NET
On TableA.Id = TableB.Id
ASP.NET
What is the difference between INTERSECT and INNER JOIN
1. INTERSECT filters duplicates and returns only DISTINCT rows that are common GridView
between the LEFT and Right Query, where as INNER JOIN does not filter the
duplicates. ASP.NET MVC

To understand this difference, insert the following row into TableA Visual Studio Tips and Tricks
Insert into TableA values (2, 'Mary', 'Female')
Java Video Tutorials
Now execute the following INTERSECT query. Notice that we get only the DISTINCT Part 1 : Video | Text | Slides
rows
Part 2 : Video | Text | Slides
Select Id, Name, Gender from TableA
Intersect Part 3 : Video | Text | Slides
Select Id, Name, Gender from TableB
Interview Questions
Result :
C#

SQL Server

Written Test

Now execute the following INNER JOIN query. Notice that the duplicate rows are not
filtered.

Select TableA.Id, TableA.Name, TableA.Gender


From TableA Inner Join TableB
On TableA.Id = TableB.Id

Result :

You can make the INNER JOIN behave like INTERSECT operator by using the
DISTINCT operator

Select DISTINCT TableA.Id, TableA.Name, TableA.Gender


From TableA Inner Join TableB
On TableA.Id = TableB.Id

Result :

2. INNER JOIN treats two NULLS as two different values. So if you are joining two
tables based on a nullable column and if both tables have NULLs in that joining column
then, INNER JOIN will not include those rows in the result-set, where as INTERSECT

https://web.archive.org/web/20211022010219/https://csharp-video-tutorials.blogspot.com/2015/09/intersect-operator-in-sql-server.html 3/5
3/12/2023 Sql server, .net and c# video tutorial: Intersect operator in sql server
treats two NULLs as a same value and it returns all matching rows.

To understand this difference, execute the following 2 insert statements


Insert into TableA values(NULL, 'Pam', 'Female')
Insert into TableB values(NULL, 'Pam', 'Female')

INTERSECT query
Select Id, Name, Gender from TableA
Intersect
Select Id, Name, Gender from TableB

Result :

INNER JOIN query


Select TableA.Id, TableA.Name, TableA.Gender
From TableA Inner Join TableB
On TableA.Id = TableB.Id

Result :

2 comments:

Anonymous November 13, 2020 at 8:53 AM


I think it will only return two rows in the case of inner join queries.
Reply

Ashish Kumar June 27, 2021 at 9:25 AM


No because, inner join doesn't remove duplicate. So it will return 3 rows
Reply

https://web.archive.org/web/20211022010219/https://csharp-video-tutorials.blogspot.com/2015/09/intersect-operator-in-sql-server.html 4/5
3/12/2023 Sql server, .net and c# video tutorial: Intersect operator in sql server

It would be great if you can help share these free resources

Newer Post Home Older Post

Subscribe to: Post Comments (Atom)

Powered by Blogger.

https://web.archive.org/web/20211022010219/https://csharp-video-tutorials.blogspot.com/2015/09/intersect-operator-in-sql-server.html 5/5

You might also like