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 * FROM
contentsWHERE 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 IF
s 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(...)
.
精彩评论