MySQL Forums
Forum List  »  Newbie

union all in a prepared statement?
Posted by: John Franco
Date: June 02, 2009 05:33PM


I would like to have a prepared statement like,

( select t1.c1 from t1 where t1.c2 >= ? limit ? )
union all ( select t1.c1 from t1 limit ? )
limit ?, 1
into @v1

That is, I want to choose a starting point in table t1, and then find the nth value greater than or equal to the starting point, wrapping around to the beginning if necessary. I want to save the value found into a variable.

I'm using a prepared statement because that's the only way I've been able to use variables for limit clauses.

The problem is, although the syntax above seems correct when I substitute values for the question marks and run it in the query browser, MySQL claims the syntax is invalid when I try to run it in a prepared statement:

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 'into @v1' at line 1

Anyone have suggestions on what to do about this? Should I open a bug?

Options: ReplyQuote

Written By
union all in a prepared statement?
June 02, 2009 05:33PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.