Cartesian product in SQL

Source: Internet
Author: User
Tags one table

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.