【问题标题】:Multiple LEFT JOIN in AccessAccess 中的多个 LEFT JOIN
【发布时间】:2011-12-20 20:54:16
【问题描述】:

我有以下查询,适用于 MySQL:

DELETE `test1`, `test2`, `test3`, `test4` FROM
`test1` LEFT JOIN `test2` ON test2.qid = test1.id
LEFT JOIN test3 ON test3.tid = test2.id
LEFT JOIN test4.qid = test1.id
WHERE test1.id = {0}

但它不适用于 MS Access。我试图在LEFT JOIN 周围添加括号,但它在 FROM 子句中给了我语法错误。 那么这个查询应该如何在 MS Access 中工作呢?

【问题讨论】:

    标签: sql ms-access sql-delete jet


    【解决方案1】:

    Access DELETE 需要一个星号 (*):DELETE * FROM ...

    此外,连接必须使用括号嵌套:

    DELETE test1.*, test2.*, test3.*, test4.*
    FROM
        (
          (
            test1 
            LEFT JOIN test2 ON test1.qid = test2.id
          )
          LEFT JOIN test3 ON test2.tid = test3.id
        )
        LEFT JOIN test4 ON test1.qid = test4.id
    WHERE test1.id = {0}
    

    这特定于 Access (Jet) SQL。

    【讨论】:

    • 虽然我对 {0} 有疑问 :)
    • 哦,谢谢,我发现我错过了上次加入时的 test4 ON 部分。
    • 如果他使用 C# 或 VB.NET,他可能想用 String.Format(sql, some_id); 替换它。
    • 是的,它是string.Format。无论如何,这里并不重要。
    【解决方案2】:

    下面是三个带有左连接的表的示例选择语句:

    SELECT 
    FROM (Table1 LEFT JOIN Table2 ON Table1.field1 = Table2.field2) 
    LEFT JOIN Table3 ON Table2.field2 = Table3.field3;
    

    您已删除的声明:

    DELETE test1.*, test2.*, test3.*, test4.* 
    FROM
    ((test1 LEFT JOIN test2 ON test2.qid = test1.id)
    LEFT JOIN test3 ON test3.tid = test2.id)
    LEFT JOIN test4.qid = test1.id)
    WHERE (((test1.id) = [SomeParameter]));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多