Given 2 tables T1 and T2.
T1 T2
A 1
B 2
C 3
What is the no: of rows that are fetched from this query?
回答是9爲什麼9行是從這個查詢中獲取的?
Given 2 tables T1 and T2.
T1 T2
A 1
B 2
C 3
What is the no: of rows that are fetched from this query?
回答是9爲什麼9行是從這個查詢中獲取的?
@Klaus Byskov Hoffmann謝謝! – nan
它是笛卡爾乘積:從一個表(3),並從另一個表中的所有行選擇所有的行(3)併合並它們,所以3 * 3 = 9。
這就是你問它做的事。您獲得了T1
的所有行和T2
的所有行。他們不只是加在一起 - 例如,如果欄目不同,那麼這種方法就行不通,但你可以用UNION
這樣做 - 它們被合併到所謂的「笛卡爾產品」中。你基本上從兩個表中獲得所有行的組合。和3*3 = 9
。
@Downvoter:請留下評論,解釋downvotes,出於普通禮貌。 –
因爲第一張表中的每條記錄都與第二張表的每條記錄一起返回,所以結果不會被過濾。
確切輸出將是:
T1 T2
A 1
A 2
A 3
B 1
B 2
B 3
C 1
C 2
C 3
(順序可能不同)
您有這些9行作爲輸出? –
Google:sql隱式「CROSS JOIN」 – onedaywhen