mysql_笛卡爾積


笛卡爾積:笛卡爾乘積是指在數學中,兩個集合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;

 

轉載請標明出處。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM