我的 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/