笛卡爾積:笛卡爾乘積是指在數學中,兩個集合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;
轉載請標明出處。