Cartesian product in SQL
When we operate on database tables, we often associate multiple tables, and we will certainly not be unfamiliar with multiple table connection queries, but it is easy to come up with huge redundant data.
Cartesian product Mathematical Concept
Cartesian product refers to a Cartesian product of two sets X and Y in mathematics (Cartesian product), also called a direct product, expressed as XXY, the first object is a member of X and the second object is one of all possible ordered pairs of Y.
The Cartesian product, also called Descartes, was proposed by a man called Descartes. In simple words, the result of multiplying the two sets.
Suppose that the set a={a, b}, set b={0, 1, 2}, the Cartesian product of two sets is {(A, 0), (A, 1), (A, 2), (b, 0), (b, 1), (b, 2)}.
Solutions
Such redundant data is not what we want, so want your results to avoid Cartesian product, do the following:
1. The column with the smallest granularity associated with the range.
2. If it is a three-sheet connection, and it is a 1:n:n relationship, it is necessary to correlate two tables and then associate the results of two tables with the third table so that we can get the results we want! More than one table!
Ref: 80869478
Cartesian product in SQL