1. <small id='Rojyt'></small><noframes id='Rojyt'>

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

      测试 MySQL 表中是否存在行的最佳方法

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

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

          <tfoot id='OHQYK'></tfoot>

              <tbody id='OHQYK'></tbody>

                <bdo id='OHQYK'></bdo><ul id='OHQYK'></ul>
                本文介绍了测试 MySQL 表中是否存在行的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我试图找出表中是否存在一行.使用 MySQL,做这样的查询是否更好:

                I'm trying to find out if a row exists in a table. Using MySQL, is it better to do a query like this:

                SELECT COUNT(*) AS total FROM table1 WHERE ...
                

                并检查总数是否为非零,或者执行这样的查询是否更好:

                and check to see if the total is non-zero or is it better to do a query like this:

                SELECT * FROM table1 WHERE ... LIMIT 1
                

                并检查是否返回了任何行?

                and check to see if any rows were returned?

                在两个查询中,WHERE 子句都使用索引.

                In both queries, the WHERE clause uses an index.

                推荐答案

                你也可以试试EXISTS:

                SELECT EXISTS(SELECT * FROM table1 WHERE ...)
                

                并且根据 文档,你可以SELECT任何东西.

                and per the documentation, you can SELECT anything.

                传统上,EXISTS 子查询以 SELECT * 开头,但它可以以 SELECT 5 或 SELECT column1 或任何东西开头.MySQL忽略此类子查询中的 SELECT 列表,因此没有区别.

                Traditionally, an EXISTS subquery starts with SELECT *, but it could begin with SELECT 5 or SELECT column1 or anything at all. MySQL ignores the SELECT list in such a subquery, so it makes no difference.

                这篇关于测试 MySQL 表中是否存在行的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:MySQL字符串替换 下一篇:如何在 MySQL 中设置初始值和自动增量?

                相关文章

                最新文章

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

                <tfoot id='Nuks4'></tfoot>
                  • <bdo id='Nuks4'></bdo><ul id='Nuks4'></ul>
                1. <small id='Nuks4'></small><noframes id='Nuks4'>