我正在尝试运行以下查询(在Sequel Pro中),但我收到以下语法错误:
'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 username FROM USER WHERE username = "TestObserver"))
{SELECT *' at line 1'
代码:
IF EXISTS (SELECT username FROM USER WHERE username = "TestObserver")
SELECT * FROM USER WHERE username = "TestObserver"
答案 0 :(得分:1)
您不能在函数之外使用if
块。而是只运行后续的SQL语句:
SELECT * FROM `USER` WHERE username = "TestObserver"
如果没有testobserver
值的用户名,则它本身就不会返回任何内容。