We help IT Professionals succeed at work.

Is it possible to set a mysql query as a variable ?

Imaging you have an basic statment
SELECT  *  FROM   post_id WHERE  wp_postmeta =2;

Open in new window

I know the
SET @variable. command but I want to set the whole statment do I have to use functions ?
or is there a way (which I tried) such as:

SET @variable = (SELECT  *  FROM   post_id WHERE  wp_postmeta =2);

Open in new window

then I can run the command using
SELECT @variable.
Comment
Watch Question

Problem resolver
Commented:
Hi,
You can have a temporary table to store relevant queries.

Each query record would have one sequence number as the key and you would pass such key number to retrieve one query.