开发者

SQL IF Doesn't work

开发者 https://www.devze.com 2023-04-13 01:34 出处:网络
Im using Wampserver 2.1 with mysql version 5.1.53. This query: SELECT * FROM `contents` WHERE 1 runs, while this query

Im using Wampserver 2.1 with mysql version 5.1.53.

This query:

SELECT * FROM `contents` WHERE 1

runs, while this query

IF 1 
SELECT * FROM `c开发者_运维问答ontents` WHERE 1

Doesn't, I get the error :

#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 1 SELECT * FROMcontentsWHERE 1' at line 1

I have looked up for 'IF' syntax dozens of times and can't find the problem. Why would this happen?


IF statements are for Flow Control Constructs within stored programs.

http://dev.mysql.com/doc/refman/5.6/en/flow-control-constructs.html


There are two IFs in MySQL: the control-flow IF and the IF statement for procedures. You'd need to either create a stored routine (where you could then use IF...THEN...), or use SELECT ... IF(...).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号