笛卡尔积:笛卡尔乘积是指在数学中,两个集合X和Y的笛卡尔积(Cartesian product),又称直积,表示为X × Y,第一个对象是X的成员而第二个对象是Y的所有可能有序对的其中一个成员。
【以上来自百度百科】
在数据库表的连接中的笛卡尔积,指两张表中,以行为最小单位,两张表行的笛卡尔积集。
即 表A={行1,行2,行3}
表B={行a,行b}
A × B = {(行1,行a),(行1,行b),(行2,行a),(行2,行b),(行3,行a),(行3,行b)}
以下三个语句的查询结果都为笛卡尔积:
select * from table1 inner join table2;
select * from table1 cross join table2;
select * from table1, table2;
以下三个语句查询结果相同,但注意性能不同:
select * from table1 a inner join table2 b on a.id = b.id;
select * from table1 a cross join table2 b where a.id = b.id;
select * from table1 a, table2 b where a.id =b.id;
转载请标明出处。