MySQL 'if exists' 错误

标签 mysql exists

我的 MySQL 查询出现错误:

if not exists(select * from tb_user where user_id=1) then
     select 'ok' as rul;
else
     select 'not' as rul;
end if;

我的问题在哪里?

最佳答案

IF 语句只能在存储函数中使用。您可以使用 IF() 函数执行您想要的操作,如下所示:

SELECT IF(EXISTS(select * from tb_user where user_id=1), 'ok', 'not') as rul;

关于MySQL 'if exists' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13985950/

相关文章:

MySQL建表语法错误

php - SQL 数组 var_dump 没有显示任何内容

sql - 在 PostgreSQL 中返回重复列

css - 如果字体存在,CSS 能否设置适当的属性?

MySQL 按中间表中的匹配数排序

php - 如何将 2 行结果回显到具有 2 列的表

php - Laravel - 通过关系中的 ID 获取有关用户的信息

mysql - 从 MySQL 结果分配 BOOL

file - 使用 cURL 检查文件是否存在于 FTPS 站点上

image - Sikuli中的图像验证/断言:如果存在IMG1或IMG2