vendredi 27 octobre 2017

MySQL - If query returns error

I want an if query like below.

set @i=1;
set @j=2;
if @i < @j then select * from test limit 1;
end if;

Im getting the below error,

1064 (42000): 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 @i < @j then select * from test limit 1' at line 1

Also tried this in procedure,

DELIMITER $$
DROP PROCEDURE IF EXISTS test $$
create procedure test ()
set @i=1;
set @j=2;
if @i < @j then select * from test limit 1;
end if;
END $$


ERROR 1064 (42000): 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 @i < @j then select * from test limit 1;
end if;
END' at line 1

Can anyone help me to fix this?

Aucun commentaire:

Enregistrer un commentaire