SQL Cross Join

Introduction

A cross join is used to generate a Cartesian product of two or more tables (contains results for each row in all tables).
In mathematics, a Cartesian product is a mathematical operation that returns multiple sets of data.
For example: two sets: X {a, b, c}and Y {1, 2, 3}the Cartesian product is: (a, 1),(a, 2),(a, 3),(b, 1),(b, 2),(b, 3),(c, 1),(c, 2),(c, 3).

In SQL, the Cartesian product of A表and B表is the result set, with each row in the first paired with each row in 表Athe second . 表BAssuming A表there are mrows and B表there are nrows, then the cross join result of A表and has rows.B表m * n

grammar

The first

select *
from A
cross join B;

the second

select *
from A, B;

Guess you like

Origin blog.csdn.net/qq_44726330/article/details/130752653