2016-02-26 95 views
-2

我有兩個表,爲了參數爲了表A和表B,我想加入它們並生成一個結果集,該表對於表B中的每一行都有一個來自表A的行。SQL將兩個不相關的表與重複記錄結合

Table A   Table B 
    NumericId  Type 
    Description 

    Contents of A Contents of B 
    1, Starting  Operation A 
    2, Completing Operation B 
    [More rows]  [NO MORE ROWS] 

    Desired result set: 
    1, Starting, Operation A 
    1, Starting, Operation B 
    2, Completing, Operation A 
    2, Completing, Operation B 
    ... etc. ... 
    (order is irrelevant) 

這可能嗎?如果是這樣,pelase可以幫助我嗎?

在此先感謝。

+7

'CROSS JOIN'是你正在尋找 – Raj

+1

那是什麼家庭作業?你到現在爲止嘗試過什麼? –

+1

請閱讀Raj建議的['Cartesian Joins'](http://www.tutorialspoint.com/sql/sql-cartesian-joins.htm) – Nitish

回答

3
select * from Table1 CROSS JOIN Table2; 
3
SELECT * FROM TAbleA CROSS JOIN TableB 
1

我解決了一個交叉連接的問題!

select 
     a.NumericId, a.Description, b.Type 
    from TableA a 
    cross join TableB b 
    order by 
     a.NumericId, a.Description, b.Type 

感謝