<tfoot id='4Wit3'></tfoot>
    • <bdo id='4Wit3'></bdo><ul id='4Wit3'></ul>

      <small id='4Wit3'></small><noframes id='4Wit3'>

        <i id='4Wit3'><tr id='4Wit3'><dt id='4Wit3'><q id='4Wit3'><span id='4Wit3'><b id='4Wit3'><form id='4Wit3'><ins id='4Wit3'></ins><ul id='4Wit3'></ul><sub id='4Wit3'></sub></form><legend id='4Wit3'></legend><bdo id='4Wit3'><pre id='4Wit3'><center id='4Wit3'></center></pre></bdo></b><th id='4Wit3'></th></span></q></dt></tr></i><div id='4Wit3'><tfoot id='4Wit3'></tfoot><dl id='4Wit3'><fieldset id='4Wit3'></fieldset></dl></div>
        <legend id='4Wit3'><style id='4Wit3'><dir id='4Wit3'><q id='4Wit3'></q></dir></style></legend>

      1. SQL DELETE 与 JOIN 另一个表的 WHERE 条件

        时间:2023-06-03
          <bdo id='sIBJu'></bdo><ul id='sIBJu'></ul>
          <tfoot id='sIBJu'></tfoot>
            <tbody id='sIBJu'></tbody>

            <small id='sIBJu'></small><noframes id='sIBJu'>

            <i id='sIBJu'><tr id='sIBJu'><dt id='sIBJu'><q id='sIBJu'><span id='sIBJu'><b id='sIBJu'><form id='sIBJu'><ins id='sIBJu'></ins><ul id='sIBJu'></ul><sub id='sIBJu'></sub></form><legend id='sIBJu'></legend><bdo id='sIBJu'><pre id='sIBJu'><center id='sIBJu'></center></pre></bdo></b><th id='sIBJu'></th></span></q></dt></tr></i><div id='sIBJu'><tfoot id='sIBJu'></tfoot><dl id='sIBJu'><fieldset id='sIBJu'></fieldset></dl></div>
            • <legend id='sIBJu'><style id='sIBJu'><dir id='sIBJu'><q id='sIBJu'></q></dir></style></legend>

                  本文介绍了SQL DELETE 与 JOIN 另一个表的 WHERE 条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我必须从 guide_category 中删除与 guide 表无关的行(死关系).

                  I have to delete rows from guide_category that have no relation with guide table (dead relations).

                  这是我想要做的,但它当然不起作用.

                  Here is what I want to do, but it of course does not work.

                  DELETE FROM guide_category AS pgc 
                   WHERE pgc.id_guide_category IN (SELECT id_guide_category 
                                                     FROM guide_category AS gc
                                                LEFT JOIN guide AS g ON g.id_guide = gc.id_guide
                                                    WHERE g.title IS NULL)
                  

                  错误:

                  不能在 FROM 子句中指定目标表 'guide_category' 进行更新

                  You can't specify target table 'guide_category' for update in FROM clause

                  推荐答案

                  由于锁定实现问题,MySQL 不允许使用 DELETE 引用受影响的表代码>更新.

                  Due to the locking implementation issues, MySQL does not allow referencing the affected table with DELETE or UPDATE.

                  你需要在这里创建一个 JOIN :

                  You need to make a JOIN here instead:

                  DELETE  gc.*
                  FROM    guide_category AS gc 
                  LEFT JOIN
                          guide AS g 
                  ON      g.id_guide = gc.id_guide
                  WHERE   g.title IS NULL
                  

                  或者只是使用NOT IN:

                  DELETE  
                  FROM    guide_category AS gc 
                  WHERE   id_guide NOT IN
                          (
                          SELECT  id_guide
                          FROM    guide
                          )
                  

                  这篇关于SQL DELETE 与 JOIN 另一个表的 WHERE 条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                1. <legend id='x6pI4'><style id='x6pI4'><dir id='x6pI4'><q id='x6pI4'></q></dir></style></legend>

                  <small id='x6pI4'></small><noframes id='x6pI4'>

                      <bdo id='x6pI4'></bdo><ul id='x6pI4'></ul>
                    • <i id='x6pI4'><tr id='x6pI4'><dt id='x6pI4'><q id='x6pI4'><span id='x6pI4'><b id='x6pI4'><form id='x6pI4'><ins id='x6pI4'></ins><ul id='x6pI4'></ul><sub id='x6pI4'></sub></form><legend id='x6pI4'></legend><bdo id='x6pI4'><pre id='x6pI4'><center id='x6pI4'></center></pre></bdo></b><th id='x6pI4'></th></span></q></dt></tr></i><div id='x6pI4'><tfoot id='x6pI4'></tfoot><dl id='x6pI4'><fieldset id='x6pI4'></fieldset></dl></div>
                      <tfoot id='x6pI4'></tfoot>

                          <tbody id='x6pI4'></tbody>