2017-10-18 186 views
0

我試圖運行下面的查詢(在續集專業),但我得到了以下語法錯誤:語法錯誤EXISTS查詢

'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" 

回答

1

您不能在功能以外使用if塊。而不是僅僅運行後續的SQL語句:

SELECT * FROM `USER` WHERE username = "TestObserver" 

如果沒有與testobserver值會已經全部由自己返回任何沒有用戶名。

+0

感謝您的回覆 – BrianM