代码之家  ›  专栏  ›  技术社区  ›  Kyra

Access 2007中的SQL-语法错误

  •  0
  • Kyra  · 技术社区  · 14 年前

    SELECT *
    FROM dbo_table1 AS t1
    JOIN dbo_table2 AS t2
    ON (
         (t1.id = t2.id)   // where the two ids match so the info in table 2 match with table 1
         OR 
         ((SELECT COUNT(*) FROM dbo_table2 AS t3 WHERE t1.id = t3.id)=0)  // there is no match but I want the row with NULL for the values from the second table
       );
    
    2 回复  |  直到 14 年前
        1
  •  0
  •   HansUp    14 年前

    如果需要dbo_table1中的所有行,无论dbo_table2中是否有匹配的行,请使用左联接。Access应接受此选项:

    SELECT *
    FROM
        dbo_table1 AS t1
        LEFT JOIN dbo_table2 AS t2
        ON t1.id = t2.id;
    
        2
  •  0
  •   Tobiasopdenbrouw    14 年前

    可以使用WHERE语句(a.id=b.id或b.id为null)进行外部/交叉连接。

    (取决于您的具体要求)