简体   繁体   中英

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

I want to join 2 tables

Table 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

Table 2:

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

what I am doing is

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

what I expect to get is

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

If you want all rows the first table combined against all rows from the second table, that's called a CROSS JOIN.

You can type it as:

select *
from table1
cross join table2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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