【问题标题】:How to merge two tables in SQL?如何在 SQL 中合并两个表?
【发布时间】:2012-12-19 03:59:49
【问题描述】:

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

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

我想检索table1 中的所有行, issueid 来自table2,条件为table1.recordno=table2.recordno

来自table1recordno 是主键。我正在使用 MS-Access 数据库。

【问题讨论】:

    标签: sql ms-access-2007


    【解决方案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
    

    【讨论】:

      【解决方案2】:
      SELECT table1.serialno,table1.recordno,table2.issueid
      FROM table1 LEFT OUTER JOIN table2
      ON  table1.recordno=table2.recordno
      

      【讨论】:

        猜你喜欢
        • 2015-05-29
        • 2020-05-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-01
        相关资源
        最近更新 更多