I want to use pollNo in limit, but it get an error:
error :Script line: 4 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 ‘pollNo,1 )as A join
poll_data on A.id=poll_data.poll_id;END’ at line 6
DELIMITER $$
DROP PROCEDURE IF EXISTS `prj`.`ret_poll` $$
CREATE PROCEDURE `prj`.`ret_poll` (IN pollNo int)
BEGIN
select * from
(select * from poll limit pollNo,1 )as A
JOIN poll_data
on A.id=poll_data.poll_id;
END $$
DELIMITER ;
What version of MySQL are you using? I think this is fixed in 5.5 and forward, but prior versions need a workaround, since they want integer constants or prepared statements.
So, prior to 5.5 you should be able to do something like the following;
You can read more about it here: http://bugs.mysql.com/bug.php?id=11918