1. <legend id='Qp7oo'><style id='Qp7oo'><dir id='Qp7oo'><q id='Qp7oo'></q></dir></style></legend>
        <bdo id='Qp7oo'></bdo><ul id='Qp7oo'></ul>

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

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

      <tfoot id='Qp7oo'></tfoot>

        如何从MySQL中的多个表中删除?

        时间:2023-08-19
          <tbody id='bjvx4'></tbody>
        <i id='bjvx4'><tr id='bjvx4'><dt id='bjvx4'><q id='bjvx4'><span id='bjvx4'><b id='bjvx4'><form id='bjvx4'><ins id='bjvx4'></ins><ul id='bjvx4'></ul><sub id='bjvx4'></sub></form><legend id='bjvx4'></legend><bdo id='bjvx4'><pre id='bjvx4'><center id='bjvx4'></center></pre></bdo></b><th id='bjvx4'></th></span></q></dt></tr></i><div id='bjvx4'><tfoot id='bjvx4'></tfoot><dl id='bjvx4'><fieldset id='bjvx4'></fieldset></dl></div>
          • <bdo id='bjvx4'></bdo><ul id='bjvx4'></ul>

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

              <tfoot id='bjvx4'></tfoot>

              <legend id='bjvx4'><style id='bjvx4'><dir id='bjvx4'><q id='bjvx4'></q></dir></style></legend>

                1. 本文介绍了如何从MySQL中的多个表中删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我试图一次从几个表中删除.我做了一些研究,并提出了这个

                  I am trying to delete from a few tables at once. I've done a bit of research, and came up with this

                  DELETE FROM `pets` p,
                              `pets_activities` pa
                        WHERE p.`order` > :order
                          AND p.`pet_id` = :pet_id
                          AND pa.`id` = p.`pet_id`
                  

                  但是,我收到此错误

                  未捕获的 Database_Exception [1064]:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'p, pets_activities pa...

                  Uncaught Database_Exception [ 1064 ]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'p, pets_activities pa...

                  我以前从来没有做过交叉表删除,所以我现在没有经验,卡住了!

                  I've never done a cross table delete before, so I'm inexperienced and stuck for now!

                  我做错了什么?

                  推荐答案

                  DELETE 语句中使用 JOIN.

                  Use a JOIN in the DELETE statement.

                  DELETE p, pa
                        FROM pets p
                        JOIN pets_activities pa ON pa.id = p.pet_id
                       WHERE p.order > :order
                         AND p.pet_id = :pet_id
                  

                  或者你可以使用...

                  DELETE pa
                        FROM pets_activities pa
                        JOIN pets p ON pa.id = p.pet_id
                   WHERE p.order > :order
                     AND p.pet_id = :pet_id
                  

                  ...仅从 pets_activities

                  参见这个.

                  对于单表删除,但具有参照完整性,还有其他方法可以使用 EXISTSNOT EXISTSINNOT IN 等等.但是上面的那个你在FROM 子句之前用别名指定要从哪些表中删除可以让你更容易地摆脱一些非常紧张的地方.我倾向于在 99% 的情况下使用 EXISTS,然后有 1% 的情况下使用这种 MySQL 语法.

                  For single table deletes, yet with referential integrity, there are other ways of doing with EXISTS, NOT EXISTS, IN, NOT IN and etc. But the one above where you specify from which tables to delete with an alias before the FROM clause can get you out of a few pretty tight spots more easily. I tend to reach out to an EXISTS in 99% of the cases and then there is the 1% where this MySQL syntax takes the day.

                  这篇关于如何从MySQL中的多个表中删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:排查“非法混合排序规则"mysql 中的错误 下一篇:1052:字段列表中的列“id"不明确

                  相关文章

                  最新文章

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

                    <legend id='0xVo1'><style id='0xVo1'><dir id='0xVo1'><q id='0xVo1'></q></dir></style></legend>

                      <tfoot id='0xVo1'></tfoot>

                        <bdo id='0xVo1'></bdo><ul id='0xVo1'></ul>

                      <small id='0xVo1'></small><noframes id='0xVo1'>