小编典典

sql语法(如果存在)

sql

为什么我得到错误:

#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 'IF EXISTS(SELECT id FROM mytable WHERE id = '1')' at line 1

询问:

IF EXISTS(SELECT id FROM mytable WHERE id = '1')

谢谢


阅读 204

收藏
2021-05-30

共1个答案

小编典典

IF EXISTS仅适用于存储过程。在存储过程之外,IF()是一个带有3个参数的函数。正确的用法是

SELECT IF(EXISTS(SELECT `column` FROM `table` WHERE `id` = `1`), 1, 0);
2021-05-30