首页 文章

如何在SQL中合并两个表?

提问于
浏览
1

我有两个表table1和table2 . 两个表都有多列 .

table1: serialno , recordno....
table2: recodno,issueid....

我想从 table1issueidtable2 中检索 table1.recordno=table2.recordno 条件下的所有行

recordno 来自 table1 是主键 . 我正在使用MS-Access数据库 .

2 回答

  • 1

    您可以使用以下任何一种联接:

    JOIN:当两个表中至少有一个匹配时返回行,

    LEFT JOIN:返回左表中的所有行,即使右表中没有匹配项,

    RIGHT JOIN:返回右表中的所有行,即使左表中没有匹配项,

    FULL JOIN:当其中一个表中存在匹配时返回行

    在你的情况下:

    SELECT table1.serialno,table1.recordno, table2.issueid
    FROM table1
    INNER JOIN table2
    ON table1.recordno=table2.recordno
    ORDER BY table1.serialno
    
  • 0
    SELECT table1.serialno,table1.recordno,table2.issueid
    FROM table1 LEFT OUTER JOIN table2
    ON  table1.recordno=table2.recordno
    

相关问题