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

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

    2. <legend id='ehvPs'><style id='ehvPs'><dir id='ehvPs'><q id='ehvPs'></q></dir></style></legend>

      MySQL 的“IF EXISTS"的使用

      时间:2023-08-17

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

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

                <legend id='M5lAO'><style id='M5lAO'><dir id='M5lAO'><q id='M5lAO'></q></dir></style></legend>
                本文介绍了MySQL 的“IF EXISTS"的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                这里有两个我想使用但返回错误消息的语句:

                Here are two statements that I'd like to work, but which return error messages:

                IF EXISTS (SELECT * FROM gdata_calendars WHERE `group` =  ? AND id = ?) SELECT 1 ELSE SELECT 0
                

                IF ((SELECT COUNT(*) FROM gdata_calendars WHERE `group` =  ? AND id = ?) > 0)  SELECT 1 ELSE SELECT 0;
                

                问号在那里是因为我在 PHP 的 PDO 中使用了参数化的、准备好的语句.但是,我也尝试过手动使用数据执行此操作,但确实不起作用.

                The question marks are there because I use parametrized, prepared, statements with PHP's PDO. However, I have also tried executing this with data manually, and it really does not work.

                虽然我想知道为什么它们每个都不起作用,但如果可以使其起作用,我更愿意使用第一个查询.

                While I'd like to know why each of them doesn't work, I would prefer to use the first query if it can be made to work.

                推荐答案

                不能在函数的 OUTSIDE 使用 IF 控制块.所以这会影响您的两个查询.

                You cannot use IF control block OUTSIDE of functions. So that affects both of your queries.

                将 EXISTS 子句转换为子查询,而不是在 IF 函数中

                Turn the EXISTS clause into a subquery instead within an IF function

                SELECT IF( EXISTS(
                             SELECT *
                             FROM gdata_calendars
                             WHERE `group` =  ? AND id = ?), 1, 0)
                

                实际上,布尔值返回为 1 或 0

                In fact, booleans are returned as 1 or 0

                SELECT EXISTS(
                         SELECT *
                         FROM gdata_calendars
                         WHERE `group` =  ? AND id = ?)
                

                这篇关于MySQL 的“IF EXISTS"的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:mysql 外键约束格式错误 下一篇:来自 GROUP_BY 的两个 LEFT JOIN 的 GROUP_CONCAT 的奇怪重

                相关文章

                最新文章

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

                    <bdo id='udsj7'></bdo><ul id='udsj7'></ul>

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

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