7/14/2023 0 Comments Ssdt in visual studio 2022![]() Alternatively, we can simply use a comma to replace CROSS JOIN notation: 1234 SELECT *FROM A, B Cross join real life application example usages Now we know how to write a query using a cross join or Cartesian product, well, we should know in which cases we could use it. 12345 SELECT *FROM ACROSS JOIN B Note: Here, star will return all columns from A and from B If we would like to cross join A with itself, we would get following error message except if we provide an alias for at least one of table A occurrences. Corresponding implementation in SQL Server In SQL Server, we can write a Cartesian product using CROSS JOIN command as follows. ![]() We will first have a look at the way to run a cross join using T-SQL. Actually, this operation is very useful in a wealth of situations and we will use it extensively in last article of this series. Its notation is ∅ or Well, we might be very confused when seeing this operation and be asking ourselves « what the hell can I do with that? ». It’s a collection of zero objects and you will find in some references, it’s also called the null set. Let’s just review some fundamentals of this theory: The elementary set is the empty set. Don’t worry, we won’t do a lot of maths here as we will focus on practical aspects that we will use when writing T-SQL queries. Set Theory and fundamentals Set definition In mathematics, we define set theory is a branch of mathematics and more particularly mathematical logic that studies collections of objects we refer to as sets. ![]() We will also have a look at more “realistic” examples using Microsoft’s AdventureWorks database. In this article, we will carry on in this way by having a look at what a set is and what we can do with it in a mathematical point of view and how it’s implemented and provided to us in SQL Server. Introduction In the previous article of this series “An introduction to set-based vs procedural programming approaches in T-SQL”, we’ve seen from a simple example that we could find actual benefit from learning set-based approach when writing T-SQL code. From mathematics to SQL Server a fast introduction to set theoryįrom mathematics to SQL Server a fast introduction to set theory Apby Jefferson Elias ![]()
0 Comments
Leave a Reply. |