Тёмный

When to use a CROSS JOIN, and grouping rows of text together using the STRING_AGG function. 

SQL Server 101
Подписаться 16 тыс.
Просмотров 7 тыс.
50% 1

You should avoid the CROSS JOIN unless you have a good reason. But what are those reasons?
My SQL Server Udemy courses are:
70-461, 70-761 Querying Microsoft SQL Server with T-SQL: rebrand.ly/querying-microsoft...
98-364: Database Fundamentals (Microsoft SQL Server): rebrand.ly/database-fundamentals
70-462 SQL Server Database Administration (DBA): rebrand.ly/sql-server-dba
Microsoft SQL Server Reporting Services (SSRS): rebrand.ly/sql-server-ssrs
SQL Server Integration Services (SSIS): rebrand.ly/sql-server-ssis
SQL Server Analysis Services (SSAS): rebrand.ly/sql-server-ssas-mdx
Microsoft Power Pivot (Excel) and SSAS (Tabular DAX model): rebrand.ly/microsoft-powerpiv...
----
Unlike the other joins, CROSS JOINs does not use the ON clause to compare rows. Instead, CROSS JOINS takes each row in one table, and joins it to every row in the second table. This means that the number of rows in the resulting query can be massive.
In this video, we will look at animals in a zoo, and ask the question: what animals has each animal seen, based on when they were at the zoo? They would not have seen animals which arrived after they left, or left before they arrived.
We'll look at answering this question using a CROSS JOIN. We'll also tidy it up using the STRING_AGG function, which was introduced in SQL Server 2017.
Here is the code to generate the ZooAnimals table:
DROP TABLE IF EXISTS ZooAnimals;
CREATE TABLE ZooAnimals
(ID int primary key,
Animal varchar(10),
StartDate date,
EndDate date);
INSERT INTO ZooAnimals
VALUES (1, 'Lion', '2023-01-01', '2023-06-30'),
(2, 'Tiger', '2023-03-01', '2023-05-30'),
(3, 'Elephant', '2023-06-01', '2024-01-31'),
(4, 'Monkey', '2023-05-01', '2023-05-31'),
(5, 'Giraffe', '2023-08-01', '2023-12-31');

Наука

Опубликовано:

 

26 янв 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 14   
@user-th9rk5iy1d
@user-th9rk5iy1d 6 месяцев назад
As I heard the voice instantly I knew it is Mr. Burton, Thanks for your udemy course.
@supersql8406
@supersql8406 11 месяцев назад
Jeeze, finally someone did a Cross Join tutorial with an elegant explanation!
@SQLServer101
@SQLServer101 11 месяцев назад
Hi SuperSQL. Glad you liked it! Phillip
@WillijahDawson
@WillijahDawson 8 месяцев назад
Great explanation i appreciate the excel comparison
@vickarkhan
@vickarkhan 2 года назад
Such a beautiful explanation. Thanks for the video.
@abdulkadirdemirci3242
@abdulkadirdemirci3242 Год назад
wonderfull explanation on that topic with perfect example as wondefull as your expression, best regards
@basheeral-momani2032
@basheeral-momani2032 11 месяцев назад
thank you for the butifull example and explanation
@minnrick7986
@minnrick7986 2 года назад
Superb explanation, thank you.
@vijayanandp8804
@vijayanandp8804 Год назад
Awesome example that thank you
@BTS-en1db
@BTS-en1db 2 года назад
Thanks for the vedio
@petrdanilov3122
@petrdanilov3122 2 года назад
Great
@sinjansengupta178
@sinjansengupta178 Месяц назад
can't it be done using self join concept?
@Retrosenescent
@Retrosenescent Год назад
Why did you use a cross join and then filter rather than just using an inner join?
@SQLServer101
@SQLServer101 Год назад
Hi Emberfly. That is another option. You would put all of the WHERE into the ON. If you wanted all of the rows in Table1 matched against all of Table2 (as per 3' of this video), then you can't do that with an INNER JOIN easily. Phillip
Далее
Куда Анджилиша снова летит???
00:16
Осторожно селеба идет 😂
00:16
Просмотров 354 тыс.
Self Join in SQL
9:09
Просмотров 41 тыс.
Calculating the first day of the week in SQL Server
8:05
Choose a phone for your mom
0:20
Просмотров 4,6 млн