Reputation: 417
I am new to MySQL and I have this basic issue using if condition:
This script works just fine
SELECT IF(TIMESTAMPDIFF(SECOND,'2017-09-26 03:11:46',CURRENT_TIMESTAMP())< 1200 ,'yes','no')
But it is not working when I do it this way
if (SELECT (TIMESTAMPDIFF(SECOND,'2017-09-26 03:11:46',CURRENT_TIMESTAMP())) < 1200)
THEN
SELECT 'YES'
ELSE
SELECT 'NO'
Upvotes: 0
Views: 584
Reputation: 11648
The second example needs to be in a stored procedure. The first example is a standard DML statement and does not share the same syntax as stored procedures.
If you check here:
https://dev.mysql.com/doc/refman/5.7/en/if.html
you can see that they state this explicitly
The IF statement for stored programs implements a basic conditional construct.
Upvotes: 2