繁体   English   中英

如何从加入两个具有 2 个不同记录用于加入键的表中获取所有记录?

[英]How can i get all records from joining two table which have 2 different records for joining key?

我想加入2张桌子

表格1:

Name   quality   identifier   views   visits   date           mmmyy
P1     high       jbjs         64      7         1-1-2020     Jan20
P2     high2      jbjs         3       0         1-2-2020     Jan20

表 2:

email  Qty_sent identifier   click   date           mmmyy
E1     2000      jbjs         45      1-23-2020     Jan20
E2     1000      jbjs         9       1-4-2020      Jan20

我正在做的是

select a.*, b.* from table1 a
inner join table2 b 
on a.identifier=b.identifier 
and a.mmmyy=b.mmmyy

我期望得到的是

Name   quality   identifier   views   visits   date           mmmyy    email  Qty_sent identifier   click   date           mmmyy
P1     high       jbjs         64      7         1-1-2020     Jan20    E1     2000      jbjs         45      1-23-2020     Jan20
P2     high2      jbjs         3       0         1-2-2020     Jan20   E1     2000      jbjs         45      1-23-2020     Jan20
P1     high       jbjs         64      7         1-1-2020     Jan20   E2     1000      jbjs         9       1-4-2020      Jan20
P2     high2      jbjs         3       0         1-2-2020     Jan20   E2     1000      jbjs         9       1-4-2020      Jan20

如果您希望将第一个表的所有行与第二个表的所有行组合起来,则称为 CROSS JOIN。

您可以将其键入为:

select *
from table1
cross join table2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM