Intersect operator in sql server
sql intersect vs join
sql server intersect example
sql server intersect vs inner join
sql server inner join remove duplicates
In this video we will discuss
1. Intersect operator in sql server
2. Difference between intersect and inner join
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1
Intersect operator retrieves the common records from both the left and the right query of the Intersect operator.
Introduced in SQL Server 2005
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
Let us understand INTERSECT operator with an example.
The following query retrieves the common records from both the left and the right query of the Intersect operator.
Select Id, Name, Gender from TableA
Intersect
Select Id, Name, Gender from TableB
We can also achieve the same thinkg using INNER join. The following INNER join query would produce the exact same result.
Select TableA.Id, TableA.Name, TableA.Gender
From TableA Inner Join TableB
On TableA.Id = TableB.Id
What is the difference between INTERSECT and INNER JOIN
1. INTERSECT filters duplicates and returns only DISTINCT rows that are common between the LEFT and Right Query, where as INNER JOIN does not filter the duplicates.
To understand this difference, insert the following row into TableA
Insert into TableA values (2, 'Mary', 'Female')
Now execute the following INTERSECT query. Notice that we get only the DISTINCT rows
Select Id, Name, Gender from TableA
Intersect
Select Id, Name, Gender from TableB
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
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
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 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
INNER JOIN query
Select TableA.Id, TableA.Name, TableA.Gender
From TableA Inner Join TableB
On TableA.Id = TableB.Id
Text version of the video
http://csharp-video-tutorials.blogspot.com/2015/09/intersect-operator-in-sql-server.html
Slides
http://csharp-video-tutorials.blogspot.com/2015/09/intersect-operator-in-sql-server_6.html
All SQL Server Text Articles
http://csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html
All SQL Server Slides
http://csharp-video-tutorials.blogspot.com/p/sql-server.html
All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd
All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Intersect operator in sql server», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.