Sql 将单个值从一个表连接到多行表-Oracle
我在Oracle中有以下表格:Sql 将单个值从一个表连接到多行表-Oracle,sql,oracle,join,Sql,Oracle,Join,我在Oracle中有以下表格: Table 1 Table 2 AllCustomers ProductCode Customers 5200000 ABC 15265 DEF 156890 在Oracle中,我想加入这两个角色,如下所示: Table 3 ProductCode Customers AllCustom
Table 1 Table 2
AllCustomers ProductCode Customers
5200000 ABC 15265
DEF 156890
在Oracle中,我想加入这两个角色,如下所示:
Table 3
ProductCode Customers AllCustomers
ABC 15265 5200000
DEF 156890 5200000
我如何连接这些表?如您所见,它们没有要加入的键字段。我只需要在新表中用相同的值填充第三列,即AllCustomers中的第三列。提前谢谢 无需加入即可实现目标,如下所示:
SELECT ProductCode, Customers, (SELECT AllCustomers FROM Table1 WHERE ROWNUM = 1)
FROM Table2
也许你可以试试交叉连接
SELECT t2.*,t1.*
FROM Table1 t1 CROSS JOIN Table2 t2
如果表1中有多个客户,您需要什么?(不止一行?)您请求的是笛卡尔连接,Oracle语法是
select*from table2 cross-join table1
——但是如果表1有多行,结果将重复表2数次,表1中每行一次。@mathguy感谢您的回答。表1总是包含一行,所以我认为交叉连接是可以的。连接两个表并不意味着表2还有一列,而是“更新”该表。OP已将联接结果显式标记为表3。那么-为什么要更新?对不起,我错过了“表3”部分。我会更新我的答案。谢谢