I’ve the following procedure which says can't reopen table why it is giving this error.Here is the query:
DECLARE rangee INT;
DECLARE uid BIGINT;
SET @rangee = plimitRange * 10;
SET @uid = puserid;
DROP TEMPORARY TABLE IF EXISTS Rangee;
CREATE TEMPORARY TABLE Rangee(max BIGINT,min BIGINT);
PREPARE STMT FROM
'INSERT INTO Rangee
select max(postid),MIN(postid) from
(
select wall.postid from wall,posts where
wall.postid = posts.postid and posts.userid=?
order by wall.postid desc LIMIT 10 OFFSET ?
)m;
';
EXECUTE STMT USING @uid,@rangee;
DEALLOCATE PREPARE STMT;
select comments.comment,comments.postid,user.name,comments.userid
from user,posts,comments where
posts.postID = comments.postid and
comments.postid<=(select max from Rangee) and
comments.postid>=(select min from Rangee) and posts.userid = puserid and
user.userid=comments.userid order by comments.postid desc;
Here I am inserting values min and max id's in a temporary table from another table so that I can then use those values to retrieve my data in the final query.But in the final query where I am specifying the range i.e the line containing (select max from Rangee) and (select min from Rangee) is giving this error.How can I solve it.The values of min and max are returning fine.
Then forget about the whole procedure, do it in one query:
That’s it.
old answer…
You don’t need a temporary table at all. Also it would have been bad to do
comments.postid <= (select max from Rangee)since this could potentially return more than one row. You should have at least usedcomments.postid <= (select MAX(max) from Rangee).Also read this.